src/Crud.php

Summary

Maintainability
A
0 mins
Test Coverage

The class Crud has an overall complexity of 50 which is very high. The configured complexity threshold is 50.
Open

class Crud extends Grid
{
    /** @var array of fields to display in Grid */
    public $displayFields;

Severity: Minor
Found in src/Crud.php by phpmd

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

class Crud extends Grid
{
    /** @var array of fields to display in Grid */
    public $displayFields;

Severity: Minor
Found in src/Crud.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 jsExecute uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            if ($action->modifier === Model\UserAction::MODIFIER_CREATE || $action->modifier === Model\UserAction::MODIFIER_UPDATE) {
                $res->addStatement($this->jsCreateNotifier($this->saveMsg));
            } elseif ($action->modifier === Model\UserAction::MODIFIER_DELETE) {
                $res->addStatement($this->jsCreateNotifier($this->deleteMsg));
Severity: Minor
Found in src/Crud.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 using static access to class '\Atk4\Core\Factory' in method 'jsCreateNotifier'.
Open

        $notifier = Factory::factory($this->notifyDefault);
Severity: Minor
Found in src/Crud.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 _getModelActions uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $actions = $this->model->getUserActions($appliesTo);
        }
Severity: Minor
Found in src/Crud.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 jsExecute uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

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

            } else {
                $this->addExecutorButton($executor);
            }
Severity: Minor
Found in src/Crud.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 unused parameters such as '$id'.
Open

        $executor->onHook(UserAction\BasicExecutor::HOOK_AFTER_EXECUTE, function (ExecutorInterface $ex, $return, $id) use ($action) {
Severity: Minor
Found in src/Crud.php by phpmd

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

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

                $js = $this->container->jsReload($this->_getReloadArgs());
Severity: Minor
Found in src/Crud.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

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

    public function onFormEdit(\Closure $fx): void
Severity: Minor
Found in src/Crud.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

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

    public function onFormAdd(\Closure $fx): void
Severity: Minor
Found in src/Crud.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

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

    public function setOnActions(string $actionName, \Closure $fx): void
Severity: Minor
Found in src/Crud.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

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

                $ex = $item['executor'];
Severity: Minor
Found in src/Crud.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

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

    public function onFormAddEdit(\Closure $fx): void
Severity: Minor
Found in src/Crud.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

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

            $actions = array_map(fn ($v) => $this->model->getUserAction($v), $this->singleScopeActions);
Severity: Minor
Found in src/Crud.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

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

    private function _getModelActions(string $appliesTo): array
Severity: Minor
Found in src/Crud.php by phpcodesniffer

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

    private function _getReloadArgs()
Severity: Minor
Found in src/Crud.php by phpcodesniffer

Line exceeds 120 characters; contains 170 characters
Open

                $executor->onHook(UserAction\ModalExecutor::HOOK_STEP, static function (UserAction\ModalExecutor $ex, string $step, Form $form) use ($onAction, $action) {
Severity: Minor
Found in src/Crud.php by phpcodesniffer

Line exceeds 120 characters; contains 159 characters
Open

    /** @var array<string, array{item: MenuItem, executor: AbstractView&ExecutorInterface}> Collection of APPLIES_TO_NO_RECORDS Scope Model action menu item */
Severity: Minor
Found in src/Crud.php by phpcodesniffer

Line exceeds 120 characters; contains 135 characters
Open

                    $this->container->js(true, $item['item']->js()->on('click.atk_crud_item', new JsFunction([], $ex->jsExecute([]))));
Severity: Minor
Found in src/Crud.php by phpcodesniffer

Line exceeds 120 characters; contains 127 characters
Open

    /** @var array<int, array<string, \Closure(Form, UserAction\ModalExecutor): void>> Callback containers for model action. */
Severity: Minor
Found in src/Crud.php by phpcodesniffer

Line exceeds 120 characters; contains 134 characters
Open

        $executor->onHook(UserAction\BasicExecutor::HOOK_AFTER_EXECUTE, function (ExecutorInterface $ex, $return, $id) use ($action) {
Severity: Minor
Found in src/Crud.php by phpcodesniffer

Line exceeds 120 characters; contains 174 characters
Open

                    ? $this->js(false, null, 'tr[data-id="' . $this->getApp()->uiPersistence->typecastAttributeSaveField($this->model->getIdField(), $this->deletedId) . '"]')
Severity: Minor
Found in src/Crud.php by phpcodesniffer

Line exceeds 120 characters; contains 133 characters
Open

            if ($action->modifier === Model\UserAction::MODIFIER_CREATE || $action->modifier === Model\UserAction::MODIFIER_UPDATE) {
Severity: Minor
Found in src/Crud.php by phpcodesniffer

Space before opening parenthesis of function call prohibited
Open

            $actions = array_map(fn ($v) => $this->model->getUserAction($v), $this->singleScopeActions);
Severity: Minor
Found in src/Crud.php by phpcodesniffer

Space before opening parenthesis of function call prohibited
Open

            $actions = array_map(fn ($v) => $this->model->getUserAction($v), $this->noRecordScopeActions);
Severity: Minor
Found in src/Crud.php by phpcodesniffer

The method _getReloadArgs is not named in camelCase.
Open

    private function _getReloadArgs()
    {
        $args = [];
        $args[$this->name . '_sort'] = $this->getSortBy();
        if ($this->paginator) {
Severity: Minor
Found in src/Crud.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 _getModelActions is not named in camelCase.
Open

    private function _getModelActions(string $appliesTo): array
    {
        if ($appliesTo === Model\UserAction::APPLIES_TO_SINGLE_RECORD && $this->singleScopeActions !== []) {
            $actions = array_map(fn ($v) => $this->model->getUserAction($v), $this->singleScopeActions);
        } elseif ($appliesTo === Model\UserAction::APPLIES_TO_NO_RECORDS && $this->noRecordScopeActions !== []) {
Severity: Minor
Found in src/Crud.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