src/Form/Control/Lookup.php

Summary

Maintainability
A
0 mins
Test Coverage

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

class Lookup extends Input
{
    use HookTrait;

    public $defaultTemplate = 'form/control/lookup.html';
Severity: Minor
Found in src/Form/Control/Lookup.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 getData has a boolean flag argument $limit, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function getData($limit = true): array
Severity: Minor
Found in src/Form/Control/Lookup.php by phpmd

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 applyLimit has a boolean flag argument $limit, which is a certain sign of a Single Responsibility Principle violation.
Open

    protected function applyLimit($limit = true): void
Severity: Minor
Found in src/Form/Control/Lookup.php by phpmd

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 jsDropdown has a boolean flag argument $when, which is a certain sign of a Single Responsibility Principle violation.
Open

    protected function jsDropdown($when = false, $action = null): JsExpressionable
Severity: Minor
Found in src/Form/Control/Lookup.php by phpmd

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

Avoid using static access to class '\Atk4\Ui\VirtualPage' in method 'initQuickNewRecord'.
Open

        $vp = VirtualPage::addTo($this->form ?? $this->getOwner());
Severity: Minor
Found in src/Form/Control/Lookup.php by phpmd

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 '\Atk4\Ui\CallbackLater' in method 'init'.
Open

        $this->callback = CallbackLater::addTo($this);
Severity: Minor
Found in src/Form/Control/Lookup.php by phpmd

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 '\Atk4\Ui\Form' in method 'initQuickNewRecord'.
Open

            $form = Form::addTo($p);
Severity: Minor
Found in src/Form/Control/Lookup.php by phpmd

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 '\Atk4\Data\Model\Scope' in method 'applySearchConditions'.
Open

            $scope = Model\Scope::createOr();
Severity: Minor
Found in src/Form/Control/Lookup.php by phpmd

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 '\Atk4\Core\Factory' in method 'initQuickNewRecord'.
Open

        $this->action = Factory::factory(array_merge($defaultSeed, $buttonSeed));
Severity: Minor
Found in src/Form/Control/Lookup.php by phpmd

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

        } else {
            $titleField = $this->titleField ?? $this->model->titleField;

            $this->model->addCondition($titleField, 'like', '%' . $query . '%');
        }
Severity: Minor
Found in src/Form/Control/Lookup.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 applyDependencyConditions uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            return;
        }
Severity: Minor
Found in src/Form/Control/Lookup.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

Avoid variables with short names like $vp. Configured minimum length is 3.
Open

        $vp = VirtualPage::addTo($this->form ?? $this->getOwner());
Severity: Minor
Found in src/Form/Control/Lookup.php by phpmd

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

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

Line exceeds 120 characters; contains 144 characters
Open

    /** @var string Set this to true, to permit "empty" selection. If you set it to string, it will be used as a placeholder for empty value. */
Severity: Minor
Found in src/Form/Control/Lookup.php by phpcodesniffer

Line exceeds 120 characters; contains 132 characters
Open

    /** @var array<array-key, mixed> Declare this property so Lookup is consistent as decorator to replace Form\Control\Dropdown. */
Severity: Minor
Found in src/Form/Control/Lookup.php by phpcodesniffer

Line exceeds 120 characters; contains 127 characters
Open

    /** @var string|null Set custom model field here to display it's value in dropdown instead of default model title field. */
Severity: Minor
Found in src/Form/Control/Lookup.php by phpcodesniffer

Line exceeds 120 characters; contains 125 characters
Open

                'form' => new JsFunction([], [new JsExpression('return []', [$this->form->formElement->js()->serialize()])]),
Severity: Minor
Found in src/Form/Control/Lookup.php by phpcodesniffer

Line exceeds 120 characters; contains 129 characters
Open

            'value' => $this->getApp()->uiPersistence->typecastAttributeSaveField($row->getField($idField), $row->get($idField)),
Severity: Minor
Found in src/Form/Control/Lookup.php by phpcodesniffer

Line exceeds 120 characters; contains 126 characters
Open

    /** @var string|null Set custom model field here to use it's value as ID in dropdown instead of default model ID field. */
Severity: Minor
Found in src/Form/Control/Lookup.php by phpcodesniffer

There are no issues that match your filters.

Category
Status