YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/handlers/MultiReferenceUpdater.php

Summary

Maintainability
A
1 hr
Test Coverage
F
55%

Function entityAfterSave has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function entityAfterSave(App\EventHandler $eventHandler)
    {
        $recordModel = $eventHandler->getRecordModel();
        $moduleName = $eventHandler->getModuleName();
        $moduleIds = Vtiger_MultiReferenceValue_UIType::getMultiReferenceModules($moduleName);
Severity: Minor
Found in modules/Vtiger/handlers/MultiReferenceUpdater.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

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

    public function entityAfterSave(App\EventHandler $eventHandler)
    {
        $recordModel = $eventHandler->getRecordModel();
        $moduleName = $eventHandler->getModuleName();
        $moduleIds = Vtiger_MultiReferenceValue_UIType::getMultiReferenceModules($moduleName);

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

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.
Open

    public function entityAfterSave(App\EventHandler $eventHandler)

Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

See

Avoid using static access to class 'Vtiger_MultiReferenceValue_UIType' in method 'entityAfterSave'.
Open

                        Vtiger_MultiReferenceValue_UIType::setRecordToCron($module, $moduleName, $recordId);

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 'Vtiger_MultiReferenceValue_UIType' in method 'entityAfterLink'.
Open

            Vtiger_MultiReferenceValue_UIType::setRecordToCron($destinationModule, $sourceModule, $params['destinationRecordId']);

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 'entityAfterSave'.
Open

                    $module = \App\Record::getType($recordId);

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\Module' in method 'entityAfterSave'.
Open

                if ($module && \in_array(\App\Module::getModuleId($module), $moduleIds)) {

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 '\Vtiger_MultiReferenceValue_UIType' in method 'entityAfterLink'.
Open

        if (\Vtiger_MultiReferenceValue_UIType::getFieldsByModules($sourceModule, $destinationModule)) {

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 'Vtiger_MultiReferenceValue_UIType' in method 'entityAfterSave'.
Open

        $moduleIds = Vtiger_MultiReferenceValue_UIType::getMultiReferenceModules($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

Avoid using static access to class '\App\Module' in method 'entityAfterSave'.
Open

                    if ($module && \in_array(\App\Module::getModuleId($module), $moduleIds)) {

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 '\Vtiger_MultiReferenceValue_UIType' in method 'entityAfterLink'.
Open

        if (\Vtiger_MultiReferenceValue_UIType::getFieldsByModules($destinationModule, $sourceModule)) {

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 'entityAfterSave'.
Open

                $module = \App\Record::getType($recordModel->get($fieldName));

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 'Vtiger_MultiReferenceValue_UIType' in method 'entityAfterLink'.
Open

            Vtiger_MultiReferenceValue_UIType::setRecordToCron($sourceModule, $destinationModule, $params['sourceRecordId']);

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 'Vtiger_MultiReferenceValue_UIType' in method 'entityAfterSave'.
Open

                    Vtiger_MultiReferenceValue_UIType::setRecordToCron($module, $moduleName, $recordModel->get($fieldName));

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

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

class Vtiger_MultiReferenceUpdater_Handler

The class Vtiger_MultiReferenceUpdater_Handler is not named in CamelCase.
Open

class Vtiger_MultiReferenceUpdater_Handler
{
    /**
     * EntityAfterLink 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 for alignment; tabs are not allowed
Open

    {

Spaces must be used for alignment; tabs are not allowed
Open

     */

Spaces must be used for alignment; tabs are not allowed
Open

                    }

Spaces must be used for alignment; tabs are not allowed
Open

     *

Spaces must be used for alignment; tabs are not allowed
Open

     */

Spaces must be used for alignment; tabs are not allowed
Open

    /**

Spaces must be used for alignment; tabs are not allowed
Open

     *

Spaces must be used for alignment; tabs are not allowed
Open

                    $module = \App\Record::getType($recordId);

Spaces must be used for alignment; tabs are not allowed
Open

        if (\Vtiger_MultiReferenceValue_UIType::getFieldsByModules($destinationModule, $sourceModule)) {

Spaces must be used for alignment; tabs are not allowed
Open

     */

Spaces must be used for alignment; tabs are not allowed
Open

    }

Spaces must be used for alignment; tabs are not allowed
Open

        $sourceModule = $params['sourceModule'];

Spaces must be used for alignment; tabs are not allowed
Open

    public function entityAfterTransferUnLink(App\EventHandler $eventHandler)

Spaces must be used for alignment; tabs are not allowed
Open

        if ($moduleIds) {

Spaces must be used for alignment; tabs are not allowed
Open

                    $recordId = $recordModel->getPreviousValue($fieldName);

Spaces must be used for alignment; tabs are not allowed
Open

        $params = $eventHandler->getParams();

Spaces must be used for alignment; tabs are not allowed
Open

        $destinationModule = $params['destinationModule'];

Spaces must be used for alignment; tabs are not allowed
Open

     * @param App\EventHandler $eventHandler

Spaces must be used for alignment; tabs are not allowed
Open

     *

Spaces must be used for alignment; tabs are not allowed
Open

    public function entityAfterSave(App\EventHandler $eventHandler)

Spaces must be used for alignment; tabs are not allowed
Open

        }

Spaces must be used for alignment; tabs are not allowed
Open

     * EntityAfterUnLink handler function.

Spaces must be used for alignment; tabs are not allowed
Open

        $this->entityAfterLink($eventHandler);

Spaces must be used for alignment; tabs are not allowed
Open

    }

Spaces must be used for alignment; tabs are not allowed
Open

                        Vtiger_MultiReferenceValue_UIType::setRecordToCron($module, $moduleName, $recordId);

Spaces must be used for alignment; tabs are not allowed
Open

    }

Spaces must be used for alignment; tabs are not allowed
Open

        }

Spaces must be used for alignment; tabs are not allowed
Open

    }

Spaces must be used for alignment; tabs are not allowed
Open

    public function entityAfterUnLink(App\EventHandler $eventHandler)

Spaces must be used for alignment; tabs are not allowed
Open

    /**

Spaces must be used for alignment; tabs are not allowed
Open

        $recordModel = $eventHandler->getRecordModel();

Spaces must be used for alignment; tabs are not allowed
Open

                if ($module && \in_array(\App\Module::getModuleId($module), $moduleIds)) {

Spaces must be used for alignment; tabs are not allowed
Open

                }

Spaces must be used for alignment; tabs are not allowed
Open

            Vtiger_MultiReferenceValue_UIType::setRecordToCron($destinationModule, $sourceModule, $params['destinationRecordId']);

Spaces must be used for alignment; tabs are not allowed
Open

    public function entityAfterTransferLink(App\EventHandler $eventHandler)

Spaces must be used for alignment; tabs are not allowed
Open

     */

Spaces must be used for alignment; tabs are not allowed
Open

    {

Spaces must be used for alignment; tabs are not allowed
Open

     * @param App\EventHandler $eventHandler

Spaces must be used for alignment; tabs are not allowed
Open

            foreach ($referenceFields as $fieldName => $fieldModel) {

Spaces must be used for alignment; tabs are not allowed
Open

     * @param App\EventHandler $eventHandler

Spaces must be used for alignment; tabs are not allowed
Open

    {

Spaces must be used for alignment; tabs are not allowed
Open

    }

Spaces must be used for alignment; tabs are not allowed
Open

        }

Spaces must be used for alignment; tabs are not allowed
Open

     * EntityAfterLink handler function.

Spaces must be used for alignment; tabs are not allowed
Open

            Vtiger_MultiReferenceValue_UIType::setRecordToCron($sourceModule, $destinationModule, $params['sourceRecordId']);

Spaces must be used for alignment; tabs are not allowed
Open

    {

Spaces must be used for alignment; tabs are not allowed
Open

     * @param App\EventHandler $eventHandler

Spaces must be used for alignment; tabs are not allowed
Open

     * EntityAfterSave function.

Spaces must be used for alignment; tabs are not allowed
Open

                }

Spaces must be used for alignment; tabs are not allowed
Open

                    Vtiger_MultiReferenceValue_UIType::setRecordToCron($module, $moduleName, $recordModel->get($fieldName));

Spaces must be used for alignment; tabs are not allowed
Open

            }

Spaces must be used for alignment; tabs are not allowed
Open

    /**

Spaces must be used for alignment; tabs are not allowed
Open

     * EntityAfterTransferUnLink handler function.

Spaces must be used for alignment; tabs are not allowed
Open

        $moduleIds = Vtiger_MultiReferenceValue_UIType::getMultiReferenceModules($moduleName);

Spaces must be used for alignment; tabs are not allowed
Open

 * @package        Handler

Spaces must be used for alignment; tabs are not allowed
Open

        if (\Vtiger_MultiReferenceValue_UIType::getFieldsByModules($sourceModule, $destinationModule)) {

Spaces must be used for alignment; tabs are not allowed
Open

        $this->entityAfterLink($eventHandler);

Spaces must be used for alignment; tabs are not allowed
Open

    /**

Spaces must be used for alignment; tabs are not allowed
Open

     *

Spaces must be used for alignment; tabs are not allowed
Open

    public function entityAfterLink(App\EventHandler $eventHandler)

Spaces must be used for alignment; tabs are not allowed
Open

     *

Spaces must be used for alignment; tabs are not allowed
Open

     */

Spaces must be used for alignment; tabs are not allowed
Open

                    if ($module && \in_array(\App\Module::getModuleId($module), $moduleIds)) {

Spaces must be used for alignment; tabs are not allowed
Open

     * EntityAfterTransferLink handler function.

Spaces must be used for alignment; tabs are not allowed
Open

                $module = \App\Record::getType($recordModel->get($fieldName));

Spaces must be used for alignment; tabs are not allowed
Open

        $this->entityAfterLink($eventHandler);

Spaces must be used for alignment; tabs are not allowed
Open

    {

Spaces must be used for alignment; tabs are not allowed
Open

            $referenceFields = $recordModel->getModule()->getFieldsByReference();

Spaces must be used for alignment; tabs are not allowed
Open

                if (!$recordModel->isNew() && false !== $recordModel->getPreviousValue($fieldName) && $fieldModel->isActiveField()) {

Spaces must be used for alignment; tabs are not allowed
Open

    /**

Spaces must be used for alignment; tabs are not allowed
Open

     * @param App\EventHandler $eventHandler

Spaces must be used for alignment; tabs are not allowed
Open

        $moduleName = $eventHandler->getModuleName();

Line exceeds 120 characters; contains 124 characters
Open

                    Vtiger_MultiReferenceValue_UIType::setRecordToCron($module, $moduleName, $recordModel->get($fieldName));

Line exceeds 120 characters; contains 125 characters
Open

            Vtiger_MultiReferenceValue_UIType::setRecordToCron($sourceModule, $destinationModule, $params['sourceRecordId']);

Line exceeds 120 characters; contains 130 characters
Open

            Vtiger_MultiReferenceValue_UIType::setRecordToCron($destinationModule, $sourceModule, $params['destinationRecordId']);

Line exceeds 120 characters; contains 133 characters
Open

                if (!$recordModel->isNew() && false !== $recordModel->getPreviousValue($fieldName) && $fieldModel->isActiveField()) {

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

class Vtiger_MultiReferenceUpdater_Handler

There are no issues that match your filters.

Category
Status