src/Form/AbstractLayout.php

Summary

Maintainability
A
0 mins
Test Coverage

The method addControl() has an NPath complexity of 408. The configured NPath complexity threshold is 200.
Open

    public function addControl(string $name, $control = [], array $fieldSeed = []): Control
    {
        if ($this->form->entity === null) {
            $this->form->setModel((new ProxyModel())->createEntity());
        }
Severity: Minor
Found in src/Form/AbstractLayout.php by phpmd

NPathComplexity

Since: 0.1

The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

Example

class Foo {
    function bar() {
        // lots of complicated code
    }
}

Source https://phpmd.org/rules/codesize.html#npathcomplexity

The method addControl() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10.
Open

    public function addControl(string $name, $control = [], array $fieldSeed = []): Control
    {
        if ($this->form->entity === null) {
            $this->form->setModel((new ProxyModel())->createEntity());
        }
Severity: Minor
Found in src/Form/AbstractLayout.php by phpmd

CyclomaticComplexity

Since: 0.1

Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

Example

// Cyclomatic Complexity = 11
class Foo {
1   public function example() {
2       if ($a == $b) {
3           if ($a1 == $b1) {
                fiddle();
4           } elseif ($a2 == $b2) {
                fiddle();
            } else {
                fiddle();
            }
5       } elseif ($c == $d) {
6           while ($c == $d) {
                fiddle();
            }
7        } elseif ($e == $f) {
8           for ($n = 0; $n < $h; $n++) {
                fiddle();
            }
        } else {
            switch ($z) {
9               case 1:
                    fiddle();
                    break;
10              case 2:
                    fiddle();
                    break;
11              case 3:
                    fiddle();
                    break;
                default:
                    fiddle();
                    break;
            }
        }
    }
}

Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

The class AbstractLayout has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13.
Open

abstract class AbstractLayout extends View
{
    use WarnDynamicPropertyTrait;

    /** Links layout to owner Form. */
Severity: Minor
Found in src/Form/AbstractLayout.php by phpmd

CouplingBetweenObjects

Since: 1.1.0

A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

Example

class Foo {
    /**
     * @var \foo\bar\X
     */
    private $x = null;

    /**
     * @var \foo\bar\Y
     */
    private $y = null;

    /**
     * @var \foo\bar\Z
     */
    private $z = null;

    public function setFoo(\Foo $foo) {}
    public function setBar(\Bar $bar) {}
    public function setBaz(\Baz $baz) {}

    /**
     * @return \SplObjectStorage
     * @throws \OutOfRangeException
     * @throws \InvalidArgumentException
     * @throws \ErrorException
     */
    public function process(\Iterator $it) {}

    // ...
}

Source https://phpmd.org/rules/design.html#couplingbetweenobjects

The method addControl uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $dropdownModel = $control instanceof Control ? $control->model : ($control['model'] ?? null);
                if ($dropdownModel !== null) {
                    $fieldSeed['type'] = $dropdownModel->getIdField()->type;
                }
Severity: Minor
Found in src/Form/AbstractLayout.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 addControl uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $field = $model->addField($name, $fieldSeed);
            }
Severity: Minor
Found in src/Form/AbstractLayout.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

Method name "_addControl" should not be prefixed with an underscore to indicate visibility
Open

    protected function _addControl(Control $control, Field $field): Control
Severity: Minor
Found in src/Form/AbstractLayout.php by phpcodesniffer

Line exceeds 120 characters; contains 123 characters
Open

        } elseif (is_a($controlClass, Control\Dropdown::class, true) || is_a($controlClass, Control\Lookup::class, true)) {
Severity: Minor
Found in src/Form/AbstractLayout.php by phpcodesniffer

Line exceeds 120 characters; contains 142 characters
Open

                $cascadeFromControl = $control instanceof Control\DropdownCascade ? $control->cascadeFrom : ($control['cascadeFrom'] ?? null);
Severity: Minor
Found in src/Form/AbstractLayout.php by phpcodesniffer

The method _addControl is not named in camelCase.
Open

    protected function _addControl(Control $control, Field $field): Control
    {
        return $this->add($control, $this->template->hasTag($field->shortName) ? $field->shortName : null);
    }
Severity: Minor
Found in src/Form/AbstractLayout.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