mambax7/adslight

View on GitHub
class/Pictures.php

Summary

Maintainability
B
4 hrs
Test Coverage

Function getAllPictures has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    public function getAllPictures(
        $criteria = [],
        $asobject = false,
        $sort = 'cod_img',
        $cat_order = 'ASC',
Severity: Minor
Found in class/Pictures.php - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method getAllPictures has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getAllPictures(
        $criteria = [],
        $asobject = false,
        $sort = 'cod_img',
        $cat_order = 'ASC',
Severity: Minor
Found in class/Pictures.php - About 1 hr to fix

    Method getAllPictures has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

            $criteria = [],
            $asobject = false,
            $sort = 'cod_img',
            $cat_order = 'ASC',
            $limit = 0,
    Severity: Minor
    Found in class/Pictures.php - About 45 mins to fix

      The method getAllPictures() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
      Open

          public function getAllPictures(
              $criteria = [],
              $asobject = false,
              $sort = 'cod_img',
              $cat_order = 'ASC',
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CyclomaticComplexity

      Since: 0.1

      Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

      Example

      // Cyclomatic Complexity = 11
      class Foo {
      1   public function example() {
      2       if ($a == $b) {
      3           if ($a1 == $b1) {
                      fiddle();
      4           } elseif ($a2 == $b2) {
                      fiddle();
                  } else {
                      fiddle();
                  }
      5       } elseif ($c == $d) {
      6           while ($c == $d) {
                      fiddle();
                  }
      7        } elseif ($e == $f) {
      8           for ($n = 0; $n < $h; $n++) {
                      fiddle();
                  }
              } else {
                  switch ($z) {
      9               case 1:
                          fiddle();
                          break;
      10              case 2:
                          fiddle();
                          break;
      11              case 3:
                          fiddle();
                          break;
                      default:
                          fiddle();
                          break;
                  }
              }
          }
      }

      Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

      The method getAllPictures has a boolean flag argument $asobject, which is a certain sign of a Single Responsibility Principle violation.
      Open

              $asobject = false,
      Severity: Minor
      Found in class/Pictures.php by phpmd

      BooleanArgumentFlag

      Since: 1.4.0

      A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

      Example

      class Foo {
          public function bar($flag = true) {
          }
      }

      Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

      The method getAllPictures uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $sql    = 'SELECT cod_img FROM ' . $xoopsDB->prefix('adslight_pictures') . "{$where_query} ORDER BY {$sort} {$cat_order}";
                  $result = $xoopsDB->query($sql, $limit, $start);
                  if (!$xoopsDB->isResultSet($result)) {
                      \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
      Severity: Minor
      Found in class/Pictures.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

      Source https://phpmd.org/rules/cleancode.html#elseexpression

      Avoid using static access to class '\XoopsDatabaseFactory' in method '__construct'.
      Open

              $this->db     = \XoopsDatabaseFactory::getDatabaseConnection();
      Severity: Minor
      Found in class/Pictures.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      The method __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      $this->load((int)$lid);
                  }
      Severity: Minor
      Found in class/Pictures.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

      Source https://phpmd.org/rules/cleancode.html#elseexpression

      The method getAllPictures uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
                  }
      Severity: Minor
      Found in class/Pictures.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

      Source https://phpmd.org/rules/cleancode.html#elseexpression

      Avoid using static access to class '\XoopsDatabaseFactory' in method 'getAllPictures'.
      Open

              $xoopsDB     = \XoopsDatabaseFactory::getDatabaseConnection();
      Severity: Minor
      Found in class/Pictures.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class 'XoopsModules\Adslight\Helper' in method '__construct'.
      Open

              $this->helper = Helper::getInstance();
      Severity: Minor
      Found in class/Pictures.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      The method __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $this->setNew();
              }
      Severity: Minor
      Found in class/Pictures.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

      Source https://phpmd.org/rules/cleancode.html#elseexpression

      Avoid unused private fields such as '$cod_img'.
      Open

          private $cod_img;
      Severity: Minor
      Found in class/Pictures.php by phpmd

      UnusedPrivateField

      Since: 0.2

      Detects when a private field is declared and/or assigned a value, but not used.

      Example

      class Something
      {
          private static $FOO = 2; // Unused
          private $i = 5; // Unused
          private $j = 6;
          public function addOne()
          {
              return $this->j++;
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

      Avoid unused private fields such as '$uid_owner'.
      Open

          private $uid_owner;
      Severity: Minor
      Found in class/Pictures.php by phpmd

      UnusedPrivateField

      Since: 0.2

      Detects when a private field is declared and/or assigned a value, but not used.

      Example

      class Something
      {
          private static $FOO = 2; // Unused
          private $i = 5; // Unused
          private $j = 6;
          public function addOne()
          {
              return $this->j++;
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

      Avoid unused private fields such as '$url'.
      Open

          private $url;
      Severity: Minor
      Found in class/Pictures.php by phpmd

      UnusedPrivateField

      Since: 0.2

      Detects when a private field is declared and/or assigned a value, but not used.

      Example

      class Something
      {
          private static $FOO = 2; // Unused
          private $i = 5; // Unused
          private $j = 6;
          public function addOne()
          {
              return $this->j++;
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

      Avoid unused private fields such as '$date_created'.
      Open

          private $date_created;
      Severity: Minor
      Found in class/Pictures.php by phpmd

      UnusedPrivateField

      Since: 0.2

      Detects when a private field is declared and/or assigned a value, but not used.

      Example

      class Something
      {
          private static $FOO = 2; // Unused
          private $i = 5; // Unused
          private $j = 6;
          public function addOne()
          {
              return $this->j++;
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

      Avoid unused parameters such as '$id'.
      Open

              $id = null,
      Severity: Minor
      Found in class/Pictures.php by phpmd

      UnusedFormalParameter

      Since: 0.2

      Avoid passing parameters to methods or constructors and then not using those parameters.

      Example

      class Foo
      {
          private function bar($howdy)
          {
              // $howdy is not used
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

      Avoid unused private fields such as '$lid'.
      Open

          private $lid;
      Severity: Minor
      Found in class/Pictures.php by phpmd

      UnusedPrivateField

      Since: 0.2

      Detects when a private field is declared and/or assigned a value, but not used.

      Example

      class Something
      {
          private static $FOO = 2; // Unused
          private $i = 5; // Unused
          private $j = 6;
          public function addOne()
          {
              return $this->j++;
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

      Avoid unused private fields such as '$title'.
      Open

          private $title;
      Severity: Minor
      Found in class/Pictures.php by phpmd

      UnusedPrivateField

      Since: 0.2

      Detects when a private field is declared and/or assigned a value, but not used.

      Example

      class Something
      {
          private static $FOO = 2; // Unused
          private $i = 5; // Unused
          private $j = 6;
          public function addOne()
          {
              return $this->j++;
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

      Avoid unused private fields such as '$date_updated'.
      Open

          private $date_updated;
      Severity: Minor
      Found in class/Pictures.php by phpmd

      UnusedPrivateField

      Since: 0.2

      Detects when a private field is declared and/or assigned a value, but not used.

      Example

      class Something
      {
          private static $FOO = 2; // Unused
          private $i = 5; // Unused
          private $j = 6;
          public function addOne()
          {
              return $this->j++;
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

      The property $date_created is not named in camelCase.
      Open

      class Pictures extends \XoopsObject
      {
          private $cod_img;
          private $title;
          private $date_created;
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      The property $date_updated is not named in camelCase.
      Open

      class Pictures extends \XoopsObject
      {
          private $cod_img;
          private $title;
          private $date_created;
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      Avoid variables with short names like $id. Configured minimum length is 3.
      Open

              $id = null,
      Severity: Minor
      Found in class/Pictures.php by phpmd

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#shortvariable

      Avoid variables with short names like $id. Configured minimum length is 3.
      Open

          public function load($id): void
      Severity: Minor
      Found in class/Pictures.php by phpmd

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#shortvariable

      The parameter $cat_order is not named in camelCase.
      Open

          public function getAllPictures(
              $criteria = [],
              $asobject = false,
              $sort = 'cod_img',
              $cat_order = 'ASC',
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      The property $uid_owner is not named in camelCase.
      Open

      class Pictures extends \XoopsObject
      {
          private $cod_img;
          private $title;
          private $date_created;
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      Avoid variables with short names like $db. Configured minimum length is 3.
      Open

          public $db;
      Severity: Minor
      Found in class/Pictures.php by phpmd

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#shortvariable

      The property $cod_img is not named in camelCase.
      Open

      class Pictures extends \XoopsObject
      {
          private $cod_img;
          private $title;
          private $date_created;
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 42 and the first side effect is on line 32.
      Open

      <?php declare(strict_types=1);
      Severity: Minor
      Found in class/Pictures.php by phpcodesniffer

      Line exceeds 120 characters; contains 134 characters
      Open

                  $sql    = 'SELECT cod_img FROM ' . $xoopsDB->prefix('adslight_pictures') . "{$where_query} ORDER BY {$sort} {$cat_order}";
      Severity: Minor
      Found in class/Pictures.php by phpcodesniffer

      Line exceeds 120 characters; contains 128 characters
      Open

                  $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('adslight_pictures') . "{$where_query} ORDER BY {$sort} {$cat_order}";
      Severity: Minor
      Found in class/Pictures.php by phpcodesniffer

      The variable $cat_order is not named in camelCase.
      Open

          public function getAllPictures(
              $criteria = [],
              $asobject = false,
              $sort = 'cod_img',
              $cat_order = 'ASC',
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCaseVariableName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name variables.

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $where_query is not named in camelCase.
      Open

          public function getAllPictures(
              $criteria = [],
              $asobject = false,
              $sort = 'cod_img',
              $cat_order = 'ASC',
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCaseVariableName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name variables.

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $where_query is not named in camelCase.
      Open

          public function getAllPictures(
              $criteria = [],
              $asobject = false,
              $sort = 'cod_img',
              $cat_order = 'ASC',
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCaseVariableName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name variables.

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $where_query is not named in camelCase.
      Open

          public function getAllPictures(
              $criteria = [],
              $asobject = false,
              $sort = 'cod_img',
              $cat_order = 'ASC',
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCaseVariableName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name variables.

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $where_query is not named in camelCase.
      Open

          public function getAllPictures(
              $criteria = [],
              $asobject = false,
              $sort = 'cod_img',
              $cat_order = 'ASC',
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCaseVariableName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name variables.

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $cat_order is not named in camelCase.
      Open

          public function getAllPictures(
              $criteria = [],
              $asobject = false,
              $sort = 'cod_img',
              $cat_order = 'ASC',
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCaseVariableName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name variables.

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $where_query is not named in camelCase.
      Open

          public function getAllPictures(
              $criteria = [],
              $asobject = false,
              $sort = 'cod_img',
              $cat_order = 'ASC',
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCaseVariableName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name variables.

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $where_query is not named in camelCase.
      Open

          public function getAllPictures(
              $criteria = [],
              $asobject = false,
              $sort = 'cod_img',
              $cat_order = 'ASC',
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCaseVariableName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name variables.

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $where_query is not named in camelCase.
      Open

          public function getAllPictures(
              $criteria = [],
              $asobject = false,
              $sort = 'cod_img',
              $cat_order = 'ASC',
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCaseVariableName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name variables.

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $where_query is not named in camelCase.
      Open

          public function getAllPictures(
              $criteria = [],
              $asobject = false,
              $sort = 'cod_img',
              $cat_order = 'ASC',
      Severity: Minor
      Found in class/Pictures.php by phpmd

      CamelCaseVariableName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name variables.

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      There are no issues that match your filters.

      Category
      Status