skqr/hateoas

View on GitHub
JsonApi/Merge/Blender.php

Summary

Maintainability
B
4 hrs
Test Coverage

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

    public function mergeLinkedResources(array &$champion, array $challenger)
    {
        static $key = 'linked';

        if (isset($champion[$key]) || isset($challenger[$key])) {
Severity: Minor
Found in JsonApi/Merge/Blender.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 mergeResourceMeta has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    public function mergeResourceMeta(array &$champion, array $challenger)
    {
        static $key = 'meta';

        if (isset($champion[$key]) || isset($challenger[$key])) {
Severity: Minor
Found in JsonApi/Merge/Blender.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 mergeTopLevelLinks has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function mergeTopLevelLinks(array &$champion, array $challenger)
    {
        static $key = 'links';

        if (isset($champion[$key]) || isset($challenger[$key])) {
Severity: Minor
Found in JsonApi/Merge/Blender.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 mergePrimaryResources has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function mergePrimaryResources(array &$champion, array $challenger)
    {
        foreach ($challenger as $key => $value) {
            if (in_array($key, static::$reservedTopLevel)) continue;

Severity: Minor
Found in JsonApi/Merge/Blender.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

Missing class import via use statement (line '67', column '31').
Open

                    throw new \LogicException(
Severity: Minor
Found in JsonApi/Merge/Blender.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 mergeLinkedResources uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

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

                    } else {
                        throw new UnmergeableResourcesException;
                    }
Severity: Minor
Found in JsonApi/Merge/Blender.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 resolveResourceObject uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            throw new UnmergeableResourcesException;
        }
Severity: Minor
Found in JsonApi/Merge/Blender.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 resolveSameType uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            throw new UnmergeableResourcesException;
        }
Severity: Minor
Found in JsonApi/Merge/Blender.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 mergeTopLevelLinks uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $champion[$key] = $links;
                }
Severity: Minor
Found in JsonApi/Merge/Blender.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 closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Open

    {
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

Expected 1 space after FUNCTION keyword; 0 found
Open

        $callback = function(array $resource) use (&$byIds) {
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

Multi-line function declarations must define one parameter per line
Open

        array $resourceA, array $resourceB
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

Multi-line function declarations must define one parameter per line
Open

        array $resourceA, array $resourceB
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

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

    {
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

Multi-line function declarations must define one parameter per line
Open

        array $collectionA, array $collectionB
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

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

    {
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

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

    {
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

Expected 1 space after FUNCTION keyword; 0 found
Open

                $compare = function(array $linkA, array $linkB) {
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

Multi-line function declarations must define one parameter per line
Open

        array $resourceA, array $resourceB
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

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

                    $champion[$key], $links, $compare
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

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

                    $champion[$key], $links, $compare
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

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

                                $champion[$key][$type], $collection
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

Inline control structures are not allowed
Open

            if (in_array($key, static::$reservedTopLevel)) continue;
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

Line exceeds 120 characters; contains 178 characters
Open

    const ERROR_MISSING_TOP_LEVEL_LINKS = "Por algún motivo desconocido dos recursos del mismo tipo intentan registrar dos plantillas de URL distintas para la misma relación.";
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

Expected 0 spaces after opening bracket; newline found
Open

        if (
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

Expected 0 spaces after opening bracket; newline found
Open

        } elseif (
Severity: Minor
Found in JsonApi/Merge/Blender.php by phpcodesniffer

There are no issues that match your filters.

Category
Status