YetiForceCompany/YetiForceCRM

View on GitHub
modules/Approvals/handlers/Approvals.php

Summary

Maintainability
A
1 hr
Test Coverage
A
100%

Function reloadApprovals has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public static function reloadApprovals(int $approvalId): void
    {
        $moduleName = 'Approvals';
        if (\App\Record::isExists($approvalId, $moduleName)) {
            $contactModal = \Vtiger_Module_Model::getInstance('Contacts');
Severity: Minor
Found in modules/Approvals/handlers/Approvals.php - About 1 hr 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

Missing class import via use statement (line '56', column '12').
Open

                        (new \App\BatchMethod([

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Missing class import via use statement (line '51', column '25').
Open

                    $dataReader = (new \App\QueryGenerator('ApprovalsRegister'))

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Missing class import via use statement (line '30', column '9').
Open

            (new \App\BatchMethod([

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Avoid using static access to class '\Vtiger_Module_Model' in method 'reloadApprovals'.
Open

            $contactModal = \Vtiger_Module_Model::getInstance('Contacts');

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 '\App\Record' in method 'reloadApprovals'.
Open

        if (\App\Record::isExists($approvalId, $moduleName)) {

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 \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

                    $dataReader = (new \App\QueryGenerator('ApprovalsRegister'))
Severity: Critical
Found in modules/Approvals/handlers/Approvals.php by phan

Call to method setFields from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

                    $dataReader = (new \App\QueryGenerator('ApprovalsRegister'))
Severity: Critical
Found in modules/Approvals/handlers/Approvals.php by phan

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class Approvals_Approvals_Handler

The class Approvals_Approvals_Handler is not named in CamelCase.
Open

class Approvals_Approvals_Handler
{
    /**
     * EntityAfterSave handler function.
     *

CamelCaseClassName

Since: 0.2

It is considered best practice to use the CamelCase notation to name classes.

Example

class class_name {
}

Source

Spaces must be used to indent lines; tabs are not allowed
Open

                'params' => [$recordModel->getId()]

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param App\EventHandler $eventHandler

Spaces must be used to indent lines; tabs are not allowed
Open

     * EntityAfterSave handler function.

Spaces must be used to indent lines; tabs are not allowed
Open

        $fieldModel = $recordModel->getField('approvals_status');

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

            $contactModal = \Vtiger_Module_Model::getInstance('Contacts');

Spaces must be used to indent lines; tabs are not allowed
Open

                            'method' => 'ApprovalsRegister_Module_Model::reloadApprovals',

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

                        ->createQuery()->createCommand()->query();

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

        $moduleName = 'Approvals';

Line exceeds 120 characters; contains 150 characters
Open

            && ($recordModel->get($fieldModel->getName()) === $acceptValue || $acceptValue === $recordModel->getPreviousValue($fieldModel->getName()))

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param int $approvalId

Spaces must be used to indent lines; tabs are not allowed
Open

                        ->setFields(['contactid'])

Spaces must be used to indent lines; tabs are not allowed
Open

                        ]))->save();

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

            && $fieldModel->isActiveField()

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

                        ->addCondition('approvalsid', $approvalId, 'eid')->setDistinct('contactid')

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    public function entityAfterSave(App\EventHandler $eventHandler)

Spaces must be used to indent lines; tabs are not allowed
Open

        $acceptValue = 'PLL_ACTIVE';

Spaces must be used to indent lines; tabs are not allowed
Open

            && ($recordModel->get($fieldModel->getName()) === $acceptValue || $acceptValue === $recordModel->getPreviousValue($fieldModel->getName()))

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        $recordModel = $eventHandler->getRecordModel();

Spaces must be used to indent lines; tabs are not allowed
Open

     * Reload approvals.

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

            foreach ($contactModal->getFieldsByType('multiReference', true) as $fieldModel) {

Spaces must be used to indent lines; tabs are not allowed
Open

            ]))->save();

Spaces must be used to indent lines; tabs are not allowed
Open

                }

Spaces must be used to indent lines; tabs are not allowed
Open

                    while ($contactId = $dataReader->readColumn(0)) {

Spaces must be used to indent lines; tabs are not allowed
Open

                            'params' => [$contactId]

Spaces must be used to indent lines; tabs are not allowed
Open

            ) {

Spaces must be used to indent lines; tabs are not allowed
Open

            (new \App\BatchMethod([

Spaces must be used to indent lines; tabs are not allowed
Open

                'method' => 'Approvals_Approvals_Handler::reloadApprovals',

Spaces must be used to indent lines; tabs are not allowed
Open

        if ($fieldModel

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return void

Spaces must be used to indent lines; tabs are not allowed
Open

            }

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    public static function reloadApprovals(int $approvalId): void

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

                if ($fieldModel->getReferenceList() === [$moduleName]) {

Spaces must be used to indent lines; tabs are not allowed
Open

                    }

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        if (\App\Record::isExists($approvalId, $moduleName)) {

Spaces must be used to indent lines; tabs are not allowed
Open

                    $dataReader = (new \App\QueryGenerator('ApprovalsRegister'))

Spaces must be used to indent lines; tabs are not allowed
Open

                        (new \App\BatchMethod([

Class name "Approvals_Approvals_Handler" is not in camel caps format
Open

class Approvals_Approvals_Handler

There are no issues that match your filters.

Category
Status