open-orchestra/open-orchestra-cms-bundle

View on GitHub
GroupBundle/Form/DataTransformer/GroupPerimeterTransformer.php

Summary

Maintainability
B
5 hrs
Test Coverage

Function reverseTransform has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

    public function reverseTransform($value)
    {
        $result = new ArrayCollection();
        if (is_array($value)) {
            foreach ($value as $type => $perimeters) {
Severity: Minor
Found in GroupBundle/Form/DataTransformer/GroupPerimeterTransformer.php - About 4 hrs 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

Method reverseTransform has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function reverseTransform($value)
    {
        $result = new ArrayCollection();
        if (is_array($value)) {
            foreach ($value as $type => $perimeters) {
Severity: Minor
Found in GroupBundle/Form/DataTransformer/GroupPerimeterTransformer.php - About 1 hr to fix

Avoid using static access to class '\OpenOrchestra\Backoffice\GeneratePerimeter\GeneratePerimeterManager' in method 'reverseTransform'.
Open

                        $name = GeneratePerimeterManager::changeNameToPath($name);

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 '\OpenOrchestra\Backoffice\GeneratePerimeter\GeneratePerimeterManager' in method 'transform'.
Open

                $key = GeneratePerimeterManager::changePathToName($path);

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

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

        $result = new ArrayCollection();

Returning type \Doctrine\Common\Collections\ArrayCollection but reverseTransform() is declared to return array
Open

        return $result;

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

                $result->set($type, $perimeterCollection);

Call to method getOwner on non-class type array
Open

        $configuration = $this->generatePerimeterManager->generatePerimeters($value->getOwner()->getSite()->getSiteId());

Call to method toArray on non-class type array
Open

        $value = $value->toArray();

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

class GroupPerimeterTransformer implements DataTransformerInterface

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

    public function __construct(GeneratePerimeterManager $generatePerimeterManager)

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

    protected $generatePerimeterManager;

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

Expected 1 space after FUNCTION keyword; 0 found
Open

            array_walk($paths, function($path) use (&$result, $items, $type) {

Expected 1 space after FUNCTION keyword; 0 found
Open

                    array_walk($perimeters, function(&$name) {

Line exceeds 120 characters; contains 121 characters
Open

        $configuration = $this->generatePerimeterManager->generatePerimeters($value->getOwner()->getSite()->getSiteId());

Line exceeds 120 characters; contains 125 characters
Open

                    $result[$type][$key] = $result[$type][$key] || preg_match('/^' . preg_quote($item, '/') . '.*$/', $path);

Expected 1 space after FOREACH keyword; 0 found
Open

                foreach($items as $item) {

There are no issues that match your filters.

Category
Status