YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
25 mins
Test Coverage
F
0%

Function editViewChangeValue has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function editViewChangeValue(App\EventHandler $eventHandler): array
    {
        $return = [];
        $recordModel = $eventHandler->getRecordModel();
        foreach (\App\Fields\Picklist::getDependencyForModule($eventHandler->getModuleName())['conditions'] as $fieldName => $values) {
Severity: Minor
Found in modules/Vtiger/handlers/PicklistDependency.php - About 25 mins 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

Avoid using static access to class '\App\Condition' in method 'editViewChangeValue'.
Open

                if (\App\Condition::checkConditions($conditions, $recordModel)) {

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\Fields\Picklist' in method 'editViewChangeValue'.
Open

}

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\Fields\Picklist' in method 'vars'.
Open

}

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

Remove the unused function parameter "$params".
Open

    public function vars(string $name, array $params, string $moduleName): ?array

Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

Noncompliant Code Example

function doSomething($a, $b) { // "$a" is unused
  return compute($b);
}

Compliant Solution

function doSomething($b) {
  return compute($b);
}

Exceptions

Functions in classes that override a class or implement interfaces are ignored.

class C extends B {

  function doSomething($a, $b) {     // no issue reported on $b
    compute($a);
  }

}

See

  • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
  • MISRA C:2012, 2.7 - There should be no unused parameters in functions
  • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
  • CERT, MSC12-CPP. - Detect and remove code that has no effect

Avoid unused parameters such as '$params'.
Open

    public function vars(string $name, array $params, string $moduleName): ?array

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

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

class Vtiger_PicklistDependency_Handler

The class Vtiger_PicklistDependency_Handler is not named in CamelCase.
Open

class Vtiger_PicklistDependency_Handler
{
    /**
     * EditViewChangeValue 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

                    $availableValues[] = $value;

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

        }

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

 * @license        YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com)

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

                if (\App\Condition::checkConditions($conditions, $recordModel)) {

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

    }

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

     * EditViewChangeValue handler function.

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

        return $return;

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

     *

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

            $availableValues = [];

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

     * @return array

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

 * @package        Handler

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

            $return['changeOptions'][$fieldName] = $availableValues;

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

 * @author        Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>

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

            foreach ($values as $value => $conditions) {

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

                }

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

     * @return array|null

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

     *

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

 * @copyright    YetiForce S.A.

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

     * @param string $name

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

 * @author        Radosław Skrzypczak <r.skrzypczak@yetiforce.com>

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

    public function editViewChangeValue(App\EventHandler $eventHandler): array

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

     * @param array  $params

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

        $recordModel = $eventHandler->getRecordModel();

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

     * @param string $moduleName

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

        return \App\EventHandler::EDIT_VIEW_CHANGE_VALUE === $name ? \App\Fields\Picklist::getDependencyForModule($moduleName)['listener'] : null;

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

     * Get variables for the current event.

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

    }

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

        $return = [];

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

        foreach (\App\Fields\Picklist::getDependencyForModule($eventHandler->getModuleName())['conditions'] as $fieldName => $values) {

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 vars(string $name, array $params, string $moduleName): ?array

Line exceeds 120 characters; contains 135 characters
Open

        foreach (\App\Fields\Picklist::getDependencyForModule($eventHandler->getModuleName())['conditions'] as $fieldName => $values) {

Line exceeds 120 characters; contains 146 characters
Open

        return \App\EventHandler::EDIT_VIEW_CHANGE_VALUE === $name ? \App\Fields\Picklist::getDependencyForModule($moduleName)['listener'] : null;

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

class Vtiger_PicklistDependency_Handler

There are no issues that match your filters.

Category
Status