Dhii/collections-abstract-base

View on GitHub

Showing 62 of 62 total issues

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

abstract class AbstractCollection extends AbstractHasher implements CollectionInterface
{
    protected $items;

    /**
Severity: Minor
Found in src/AbstractCollection.php by phpmd

AbstractCollection has 23 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class AbstractCollection extends AbstractHasher implements CollectionInterface
{
    protected $items;

    /**
Severity: Minor
Found in src/AbstractCollection.php - About 2 hrs to fix

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

        protected function _arraySearch(&$array, $value, $strict = false)
        {
            // Regular array matching
            if (is_array($array)) {
                return array_search($value, $array, $strict);
    Severity: Minor
    Found in src/AbstractCollection.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 _arrayUnset has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function _arrayUnset(&$array, $key)
        {
            if (is_array($array)) {
                if (isset($array[$key])) {
                    unset($array[$key]);
    Severity: Minor
    Found in src/AbstractCollection.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

    Avoid too many return statements within this method.
    Open

                return false;
    Severity: Major
    Found in src/AbstractCollection.php - About 30 mins to fix

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

          public function _findItem($item, $strict = false)
      Severity: Minor
      Found in src/AbstractCollection.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 too many return statements within this method.
      Open

                  return $array->removeItemByKey($key);
      Severity: Major
      Found in src/AbstractCollection.php - About 30 mins to fix

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

            protected function _arraySearch(&$array, $value, $strict = false)
        Severity: Minor
        Found in src/AbstractCollection.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 parameters such as '$item'.
        Open

            protected function _getItemUniqueKey($item)
        Severity: Minor
        Found in src/AbstractCollection.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 local variables such as '$_item'.
        Open

                    foreach ($list as $_item) {
        Severity: Minor
        Found in src/AbstractIterableCollection.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 assigning values to variables in if clauses and the like (line '134', column '14').
        Open

            protected function _removeItem($item)
            {
                if (($key = $this->_findItem($item, true)) !== false) {
                    return $this->_arrayUnset($this->items, $key);
                }
        Severity: Minor
        Found in src/AbstractCollection.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

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

                foreach ($items as $_key => $_item) {
        Severity: Minor
        Found in src/AbstractCollection.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

        The variable $_value is not named in camelCase.
        Open

            protected function _arraySearch(&$array, $value, $strict = false)
            {
                // Regular array matching
                if (is_array($array)) {
                    return array_search($value, $array, $strict);
        Severity: Minor
        Found in src/AbstractCollection.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 $_idx is not named in camelCase.
        Open

            protected function _arraySearch(&$array, $value, $strict = false)
            {
                // Regular array matching
                if (is_array($array)) {
                    return array_search($value, $array, $strict);
        Severity: Minor
        Found in src/AbstractCollection.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 $_value is not named in camelCase.
        Open

            protected function _arraySearch(&$array, $value, $strict = false)
            {
                // Regular array matching
                if (is_array($array)) {
                    return array_search($value, $array, $strict);
        Severity: Minor
        Found in src/AbstractCollection.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 $_item is not named in camelCase.
        Open

            protected function _addItems($items)
            {
                foreach ($items as $_key => $_item) {
                    $this->_validateItem($_item);
                    $this->_addItem($_item);
        Severity: Minor
        Found in src/AbstractCollection.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 $_idx is not named in camelCase.
        Open

            protected function _arraySearch(&$array, $value, $strict = false)
            {
                // Regular array matching
                if (is_array($array)) {
                    return array_search($value, $array, $strict);
        Severity: Minor
        Found in src/AbstractCollection.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 $_item is not named in camelCase.
        Open

            public function _arrayCount(&$list)
            {
                if (is_array($list)) {
                    return count($list);
                }
        Severity: Minor
        Found in src/AbstractIterableCollection.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 $_value is not named in camelCase.
        Open

            protected function _arraySearch(&$array, $value, $strict = false)
            {
                // Regular array matching
                if (is_array($array)) {
                    return array_search($value, $array, $strict);
        Severity: Minor
        Found in src/AbstractCollection.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 $_item is not named in camelCase.
        Open

            protected function _addItems($items)
            {
                foreach ($items as $_key => $_item) {
                    $this->_validateItem($_item);
                    $this->_addItem($_item);
        Severity: Minor
        Found in src/AbstractCollection.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

        Severity
        Category
        Status
        Source
        Language