nabbar/SwaggerValidator-PHP

View on GitHub
src/Common/Collection.php

Summary

Maintainability
A
2 hrs
Test Coverage

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

class Collection implements \Countable, \IteratorAggregate, \ArrayAccess, \Serializable, \JsonSerializable
{

    /**
     *
Severity: Minor
Found in src/Common/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

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

class Collection implements \Countable, \IteratorAggregate, \ArrayAccess, \Serializable, \JsonSerializable
{

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

    Function jsonSerialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        public function jsonSerialize()
        {
            if ($this->originTypeArray === true) {
                $result = array();
            }
    Severity: Minor
    Found in src/Common/Collection.php - About 25 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 using undefined variables such as '$this' which will lead to PHP notices.
    Open

                $this->__storeData($key, $value);
    Severity: Minor
    Found in src/Common/Collection.php by phpmd

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Missing class import via use statement (line '138', column '20').
    Open

            return new \ArrayIterator($this);
    Severity: Minor
    Found in src/Common/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

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

                $result = new \stdClass();
    Severity: Minor
    Found in src/Common/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

    Missing class import via use statement (line '48', column '23').
    Open

                throw new \Exception('Error the key (' . gettype($key) . ') is not a string or an integer : ' . json_encode($key));
    Severity: Minor
    Found in src/Common/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 __storeData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            else {
                $this->collection[$key] = $value;
            }
    Severity: Minor
    Found in src/Common/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 jsonSerialize uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                else {
                    $result->$key = $value;
                }
    Severity: Minor
    Found in src/Common/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 jsonSerialize uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            else {
                $result = new \stdClass();
            }
    Severity: Minor
    Found in src/Common/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 unserialize uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            else {
                $this->collection = $data;
            }
    Severity: Minor
    Found in src/Common/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 __storeData is not named in camelCase.
    Open

        protected function __storeData($key, $value = null)
        {
            if (property_exists($this, $key)) {
                $this->$key = $value;
            }
    Severity: Minor
    Found in src/Common/Collection.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