open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/Form/DataTransformer/AbstractReferenceKeywordTransformer.php

Summary

Maintainability
A
1 hr
Test Coverage

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

    protected function partialReverseTransform($keywords, $asString = true)
    {
        $keywordArray = $this->getKeywordAsArray($keywords);
        $referenceKeywords = new ArrayCollection();

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 transform has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function transform($keywords)
    {
        if (null === $keywords) {
            return '';
        }
Severity: Minor
Found in Backoffice/Form/DataTransformer/AbstractReferenceKeywordTransformer.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

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

    protected function partialReverseTransform($keywords, $asString = true)

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

                } else {
                    throw new NotFoundedKeywordException();
                }

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

                } else {
                    throw new NotFoundedKeywordException();
                }

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

Call to method add from undeclared class \Doctrine\Common\Collections\ArrayCollection
Open

                    $referenceKeywords->add($keywordDocument);

Call to method find from undeclared class \OpenOrchestra\ModelInterface\Repository\KeywordRepositoryInterface
Open

                $keywordDocument = $this->keywordRepository->find($keyword);

Parameter $keywordRepository has undeclared type \OpenOrchestra\ModelInterface\Repository\KeywordRepositoryInterface
Open

    public function __construct(

Call to method find from undeclared class \OpenOrchestra\ModelInterface\Repository\KeywordRepositoryInterface
Open

                $keywordDocument = $this->keywordRepository->find($keyword);

Call to method getId from undeclared class \OpenOrchestra\ModelInterface\Model\KeywordInterface
Open

                    $keywords = str_replace($keyword, $keywordDocument->getId(), $keywords);

Call to method __construct from undeclared class \Doctrine\Common\Collections\ArrayCollection
Open

        $referenceKeywords = new ArrayCollection();

Class implements undeclared interface \Symfony\Component\Form\DataTransformerInterface
Open

abstract class AbstractReferenceKeywordTransformer implements DataTransformerInterface

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

        KeywordToDocumentManager $keywordToDocumentManager,

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 $keywordToDocumentManager. Keep variable name length under 20.
Open

    protected $keywordToDocumentManager;

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 a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
Open

    ){

There are no issues that match your filters.

Category
Status