Dhii/collections-abstract-base

View on GitHub
src/AbstractCollection.php

Summary

Maintainability
B
5 hrs
Test Coverage

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

      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 _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

        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 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 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 '$_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 $_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 $_key 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

            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 method _addItems 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

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _setItem is not named in camelCase.
        Open

            protected function _setItem($key, $item)
            {
                return $this->_arraySet($this->items, $item, $key);
            }
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _hasItemKey is not named in camelCase.
        Open

            protected function _hasItemKey($key)
            {
                return $this->_arrayKeyExists($this->items, $key);
            }
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _arrayGet is not named in camelCase.
        Open

            protected function _arrayGet(&$list, $key, $default = null)
            {
                if (is_array($list)) {
                    return isset($list[$key])
                        ? $list[$key]
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _arrayConvert is not named in camelCase.
        Open

            protected function _arrayConvert(&$list)
            {
                if (is_array($list)) {
                    return $list;
                }
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _addItem is not named in camelCase.
        Open

            protected function _addItem($item)
            {
                $key = $this->_getItemUniqueKey($item);
        
                return $this->_arraySet($this->items, $item, $key);
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _hasItem is not named in camelCase.
        Open

            protected function _hasItem($item)
            {
                return $this->_findItem($item, true) !== false;
            }
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _getItemKey is not named in camelCase.
        Open

            protected function _getItemKey($item)
            {
                return $this->_hash($item);
            }
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _isValidItem is not named in camelCase.
        Open

            protected function _isValidItem($item)
            {
                try {
                    $this->_validateItem($item);
                } catch (Exception $ex) {
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _findItem is not named in camelCase.
        Open

            public function _findItem($item, $strict = false)
            {
                return $this->_arraySearch($this->items, $item, $strict);
            }
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _arraySearch 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

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _validateItemList is not named in camelCase.
        Open

            protected function _validateItemList($items)
            {
                if (!is_array($items) && !($items instanceof \Traversable)) {
                    throw new UnexpectedValueException(sprintf('Must be a valid item list'));
                }
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _getItem is not named in camelCase.
        Open

            protected function _getItem($key, $default = null)
            {
                return $this->_arrayGet($this->items, $key, $default);
            }
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _getItemUniqueKey is not named in camelCase.
        Open

            protected function _getItemUniqueKey($item)
            {
                return count($this->items);
            }
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _arrayKeyExists is not named in camelCase.
        Open

            protected function _arrayKeyExists(&$list, $key)
            {
                if (is_array($list)) {
                    return array_key_exists($key, $list);
                }
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _setItems is not named in camelCase.
        Open

            protected function _setItems($items)
            {
                $this->_validateItemList($items);
                $this->items = $items;
        
        
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _removeItem is not named in camelCase.
        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

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _arraySet is not named in camelCase.
        Open

            protected function _arraySet(&$list, $item, $key)
            {
                if (is_array($list)) {
                    $list[$key] = $item;
        
        
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _validateItem is not named in camelCase.
        Open

            abstract protected function _validateItem($item);
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _construct is not named in camelCase.
        Open

            protected function _construct()
            {
                $this->items = array();
            }
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _getItems is not named in camelCase.
        Open

            protected function _getItems()
            {
                return $this->items;
            }
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        The method _arrayUnset is not named in camelCase.
        Open

            protected function _arrayUnset(&$array, $key)
            {
                if (is_array($array)) {
                    if (isset($array[$key])) {
                        unset($array[$key]);
        Severity: Minor
        Found in src/AbstractCollection.php by phpmd

        CamelCaseMethodName

        Since: 0.2

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

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        There are no issues that match your filters.

        Category
        Status