Showing 18 of 18 total issues

Collection has 35 functions (exceeds 20 allowed). Consider refactoring.
Open

class Collection extends \ArrayIterator
{
    /**
     * Constructs Collection object
     *
Severity: Minor
Found in src/Collection.php - About 4 hrs to fix

    File Collection.php has 331 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php namespace Clean\Data;
    
    use Closure;
    use InvalidArgumentException;
    use LogicException;
    Severity: Minor
    Found in src/Collection.php - About 3 hrs to fix

      The class Collection has 23 public methods. Consider refactoring Collection to keep number of public methods under 10.
      Open

      class Collection extends \ArrayIterator
      {
          /**
           * Constructs Collection object
           *
      Severity: Minor
      Found in src/Collection.php by phpmd

      TooManyPublicMethods

      Since: 0.1

      A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

      By default it ignores methods starting with 'get' or 'set'.

      Example

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

      The class Collection has an overall complexity of 86 which is very high. The configured complexity threshold is 50.
      Open

      class Collection extends \ArrayIterator
      {
          /**
           * Constructs Collection object
           *
      Severity: Minor
      Found in src/Collection.php by phpmd

      Function getAllValuesForProperty has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getAllValuesForProperty($name)
          {
              $values = [];
              foreach ($this as $entity) {
                  if (isset($entity->$name)) {
      Severity: Minor
      Found in src/Collection.php - About 1 hr 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

      Function bindCollection has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          public function bindCollection(Collection $collection, array $compareKeys, $propertyName)
          {
              $reflection = new \ReflectionClass($collection);
      
              $fromKey = key($compareKeys);
      Severity: Minor
      Found in src/Collection.php - About 55 mins 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

      Function append has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          public function append($data)
          {
              if (is_array($data) || $data instanceof \Traversable) {
                  foreach ($data as $entity) {
                      if (!$entity instanceof Entity) {
      Severity: Minor
      Found in src/Collection.php - About 45 mins 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

      Function groupByField has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          private function groupByField($name)
          {
              $collection = $this->getNewCollection();
              foreach ($this as $entity) {
                  if (!isset($entity->$name) || $entity->$name === null) {
      Severity: Minor
      Found in src/Collection.php - About 35 mins 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

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

          public function search($field, $value, $strict = false)
      Severity: Minor
      Found in src/Collection.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

      Missing class import via use statement (line '578', column '27').
      Open

              $reflection = new \ReflectionClass($collection);
      Severity: Minor
      Found in src/Collection.php by phpmd

      MissingImport

      Since: 2.7.0

      Importing all external classes in a file through use statements makes them clearly visible.

      Example

      function make() {
          return new \stdClass();
      }

      Source http://phpmd.org/rules/cleancode.html#MissingImport

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

          public function has($field, $value, $strict = false)
      Severity: Minor
      Found in src/Collection.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

      Avoid unused local variables such as '$offset'.
      Open

              foreach ($this as $offset => $entity) {
      Severity: Minor
      Found in src/Collection.php by phpmd

      UnusedLocalVariable

      Since: 0.2

      Detects when a local variable is declared and/or assigned, but not used.

      Example

      class Foo {
          public function doSomething()
          {
              $i = 5; // Unused
          }
      }

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

      Avoid unused local variables such as '$entity'.
      Open

              foreach ($this as $key => $entity) {
      Severity: Minor
      Found in src/Collection.php by phpmd

      UnusedLocalVariable

      Since: 0.2

      Detects when a local variable is declared and/or assigned, but not used.

      Example

      class Foo {
          public function doSomething()
          {
              $i = 5; // Unused
          }
      }

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

      Avoid unused private methods such as 'groupByField'.
      Open

          private function groupByField($name)
          {
              $collection = $this->getNewCollection();
              foreach ($this as $entity) {
                  if (!isset($entity->$name) || $entity->$name === null) {
      Severity: Minor
      Found in src/Collection.php by phpmd

      UnusedPrivateMethod

      Since: 0.2

      Unused Private Method detects when a private method is declared but is unused.

      Example

      class Something
      {
          private function foo() {} // unused
      }

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

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

                  } else {
                      $values[] = $entity->$propertyName;
                  }
      Severity: Minor
      Found in src/Collection.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 getAllValuesForProperty uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                          } else {
                              $values[] = $value;
                          }
      Severity: Minor
      Found in src/Collection.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 assigning values to variables in if clauses and the like (line '590', column '45').
      Open

          public function bindCollection(Collection $collection, array $compareKeys, $propertyName)
          {
              $reflection = new \ReflectionClass($collection);
      
              $fromKey = key($compareKeys);
      Severity: Minor
      Found in src/Collection.php by phpmd

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

      Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

              } else {
                  parent::append($data);
              }
      Severity: Minor
      Found in src/Collection.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

      Severity
      Category
      Status
      Source
      Language