skqr/hateoas

View on GitHub
JsonApi/Serializer/LinkedResourcesSerializer.php

Summary

Maintainability
C
7 hrs
Test Coverage

Method processLinkedResources has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function processLinkedResources(
        ResourceCollectionInterface $resources,
        array $include,
        LinkedResourcesSerialization $resourcesSerialization,
        $depth = 0
Severity: Major
Found in JsonApi/Serializer/LinkedResourcesSerializer.php - About 2 hrs to fix

    Method processToManyRelationship has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function processToManyRelationship(
            ResourceCollectionInterface $resources,
            $relationshipName,
            array &$linkedResources,
            LinkedResourcesSerialization $resourcesSerialization
    Severity: Minor
    Found in JsonApi/Serializer/LinkedResourcesSerializer.php - About 1 hr to fix

      Method processToOneRelationship has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function processToOneRelationship(
              ResourceCollectionInterface $resources,
              $relationshipName,
              array &$linkedResources,
              LinkedResourcesSerialization $resourcesSerialization
      Severity: Minor
      Found in JsonApi/Serializer/LinkedResourcesSerializer.php - About 1 hr to fix

        Function processLinkedResources has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            private function processLinkedResources(
                ResourceCollectionInterface $resources,
                array $include,
                LinkedResourcesSerialization $resourcesSerialization,
                $depth = 0
        Severity: Minor
        Found in JsonApi/Serializer/LinkedResourcesSerializer.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 processToManyRelationship has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            private function processToManyRelationship(
                ResourceCollectionInterface $resources,
                $relationshipName,
                array &$linkedResources,
                LinkedResourcesSerialization $resourcesSerialization
        Severity: Minor
        Found in JsonApi/Serializer/LinkedResourcesSerializer.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 processToOneRelationship has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            private function processToOneRelationship(
                ResourceCollectionInterface $resources,
                $relationshipName,
                array &$linkedResources,
                LinkedResourcesSerialization $resourcesSerialization
        Severity: Minor
        Found in JsonApi/Serializer/LinkedResourcesSerializer.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

        Avoid using undefined variables such as '$relationships' which will lead to PHP notices.
        Open

                                implode('.', $relationships)

        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

        Avoid using static access to class '\GoIntegro\Hateoas\JsonApi\EntityResource' in method 'processToManyRelationship'.
        Open

                        = EntityResource::normalizeToManyRelation(
                            $collection, $relationshipName
                        );

        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 '\GoIntegro\Hateoas\JsonApi\EntityResource' in method 'processToManyRelationship'.
        Open

                                EntityResource::getStringId($entity)

        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 '\GoIntegro\Hateoas\JsonApi\ResourceCollection' in method 'processLinkedResources'.
        Open

                            ResourceCollection::buildFromArray($linkedResources),

        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 processToManyRelationship uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                        } else {
                            // @todo This should never happen.
                            throw new SerializationException(sprintf(
                                self::ERROR_INHERITANCE_MAPPING,
                                implode('.', $relationships)

        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 '\GoIntegro\Hateoas\JsonApi\EntityResource' in method 'addLinkedResource'.
        Open

                        $relationship->type, EntityResource::getStringId($entity)

        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 processLinkedResources uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    } else {
                        $message = sprintf(
                            self::ERROR_UNKOWN_RELATIONSHIP, $relationshipName
                        );
                        throw new InvalidRelationshipException($message);

        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 '\GoIntegro\Hateoas\JsonApi\EntityResource' in method 'processToOneRelationship'.
        Open

                    EntityResource::validateToOneRelation(
                        $entity, $relationshipName
                    );

        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 '\GoIntegro\Hateoas\JsonApi\EntityResource' in method 'processToOneRelationship'.
        Open

                            EntityResource::getStringId($entity)

        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 unused local variables such as '$relationOfRelation'.
        Open

                $relationOfRelation = [];

        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 '$relationships'.
        Open

                                implode('.', $relationships)

        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 excessively long variable names like $resourcesSerialization. Keep variable name length under 20.
        Open

                LinkedResourcesSerialization $resourcesSerialization

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        Avoid excessively long variable names like $resourcesSerialization. Keep variable name length under 20.
        Open

                LinkedResourcesSerialization $resourcesSerialization

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        Avoid excessively long variable names like $resourcesSerialization. Keep variable name length under 20.
        Open

                LinkedResourcesSerialization $resourcesSerialization

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        Avoid excessively long variable names like $resourcesSerialization. Keep variable name length under 20.
        Open

                $resourcesSerialization = new LinkedResourcesSerialization;

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        Avoid excessively long variable names like $resourcesSerialization. Keep variable name length under 20.
        Open

                LinkedResourcesSerialization $resourcesSerialization,

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        There must be one USE keyword per declaration
        Open

        use GoIntegro\Hateoas\JsonApi\ResourceEntityInterface,

        The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
        Open

            {

        The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
        Open

            {

        The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
        Open

            {

        The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
        Open

            {

        Only one argument is allowed per line in a multi-line function call
        Open

                            $collection, $relationshipName

        Only one argument is allowed per line in a multi-line function call
        Open

                            self::ERROR_UNKOWN_RELATIONSHIP, $relationshipName

        Only one argument is allowed per line in a multi-line function call
        Open

                            $relationship, $entity, $resourcesSerialization

        Only one argument is allowed per line in a multi-line function call
        Open

                        $entity, $relationshipName

        Only one argument is allowed per line in a multi-line function call
        Open

                        $relationship, $entity, $resourcesSerialization

        Only one argument is allowed per line in a multi-line function call
        Open

                    $resource, $this->securityContext, $fields

        Only one argument is allowed per line in a multi-line function call
        Open

                        $relationship, $entity, $resourcesSerialization

        Only one argument is allowed per line in a multi-line function call
        Open

                            self::ERROR_UNKOWN_RELATIONSHIP, $relationshipName

        Only one argument is allowed per line in a multi-line function call
        Open

                        $relationship->type, EntityResource::getStringId($entity)

        Only one argument is allowed per line in a multi-line function call
        Open

                            $relationship, $entity, $resourcesSerialization

        Only one argument is allowed per line in a multi-line function call
        Open

                            self::ERROR_UNKOWN_RELATIONSHIP, $relationshipName

        Only one argument is allowed per line in a multi-line function call
        Open

                    $resource, $this->securityContext, $fields

        Line exceeds 120 characters; contains 159 characters
        Open

                ERROR_LINK_ONLY_RELATIONSHIP = "The relationship \"%s\" cannot be included, possibly because of its size. You must fetch this resource by getting %s.",

        Line exceeds 120 characters; contains 132 characters
        Open

                ERROR_INHERITANCE_MAPPING = "The mapping inheritance in the ORM for the relationship \"%s\" is not being properly handled.",

        Expected 0 spaces after opening bracket; newline found
        Open

                if (

        Expected 0 spaces after opening bracket; newline found
        Open

                    if (

        There are no issues that match your filters.

        Category
        Status