src/Form/Control/Dropdown.php

Summary

Maintainability
A
0 mins
Test Coverage

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

        } else {
            if ($this->renderRowFunction) {
                foreach ($this->values as $key => $value) {
                    $this->_addCallBackRow($value, $key);
                }
Severity: Minor
Found in src/Form/Control/Dropdown.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 htmlRenderValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $this->_renderItemsForValues();
            }
Severity: Minor
Found in src/Form/Control/Dropdown.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 _renderItemsForValues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $this->_tItem->del('Icon');
                }
Severity: Minor
Found in src/Form/Control/Dropdown.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 _renderItemsForValues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $this->_tItem->set('title', $val || is_numeric($val) ? (string) $val : '');
            }
Severity: Minor
Found in src/Form/Control/Dropdown.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 htmlRenderValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                // for standard model rendering, only load ID and title field
                $this->model->setOnlyFields([$this->model->titleField, $this->model->idField]);
                $this->_renderItemsForModel();
            }
Severity: Minor
Found in src/Form/Control/Dropdown.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 _addCallBackRow uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $res = ($this->renderRowFunction)($row, $key);
            $this->_tItem->set('value', (string) $res['value']);
        }
Severity: Minor
Found in src/Form/Control/Dropdown.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 property $_tItem is not named in camelCase.
Open

class Dropdown extends Input
{
    public $defaultTemplate = 'form/control/dropdown.html';

    public string $inputType = 'hidden';
Severity: Minor
Found in src/Form/Control/Dropdown.php by phpmd

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

The property $_tIcon is not named in camelCase.
Open

class Dropdown extends Input
{
    public $defaultTemplate = 'form/control/dropdown.html';

    public string $inputType = 'hidden';
Severity: Minor
Found in src/Form/Control/Dropdown.php by phpmd

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

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

    protected function _renderItemsForModel(): void

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

    protected function _addCallBackRow($row, $key = null): void

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

    protected function _renderItemsForValues(): void

Property name "$_tItem" should not be prefixed with an underscore to indicate visibility
Open

    protected HtmlTemplate $_tItem;

Property name "$_tIcon" should not be prefixed with an underscore to indicate visibility
Open

    protected HtmlTemplate $_tIcon;

Line exceeds 120 characters; contains 133 characters
Open

            $this->_tItem->set('value', $this->getApp()->uiPersistence->typecastAttributeSaveField($this->model->getIdField(), $id));

Line exceeds 120 characters; contains 146 characters
Open

     * @var \Closure<T of Model>(T): array{title: mixed, icon?: mixed}|\Closure(mixed, array-key): array{value: mixed, title: mixed, icon?: mixed}

Line exceeds 120 characters; contains 143 characters
Open

            $this->_tItem->set('value', $this->getApp()->uiPersistence->typecastAttributeSaveField($this->model->getIdField(), $row->getId()));

The method _renderItemsForValues is not named in camelCase.
Open

    protected function _renderItemsForValues(): void
    {
        foreach ($this->values as $key => $val) {
            $this->_tItem->set('value', (string) $key);
            if (is_array($val)) {
Severity: Minor
Found in src/Form/Control/Dropdown.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

The method _renderItemsForModel is not named in camelCase.
Open

    protected function _renderItemsForModel(): void
    {
        foreach ($this->model as $id => $row) {
            $title = $row->getTitle();
            $this->_tItem->set('value', $this->getApp()->uiPersistence->typecastAttributeSaveField($this->model->getIdField(), $id));
Severity: Minor
Found in src/Form/Control/Dropdown.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

The method _addCallBackRow is not named in camelCase.
Open

    protected function _addCallBackRow($row, $key = null): void
    {
        if ($this->model !== null) {
            $res = ($this->renderRowFunction)($row);
            $this->_tItem->set('value', $this->getApp()->uiPersistence->typecastAttributeSaveField($this->model->getIdField(), $row->getId()));
Severity: Minor
Found in src/Form/Control/Dropdown.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