YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/relations/GetDependentsList.php

Summary

Maintainability
A
35 mins
Test Coverage
F
21%

Function delete has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function delete(int $sourceRecordId, int $destinationRecordId): bool
    {
        $moduleModel = $this->relationModel->getRelationModuleModel();
        $parentModuleName = $this->relationModel->getParentModuleModel()->getName();
        $result = false;
Severity: Minor
Found in modules/Vtiger/relations/GetDependentsList.php - About 35 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 assigning values to variables in if clauses and the like (line '82', column '7').
Open

    public function delete(int $sourceRecordId, int $destinationRecordId): bool
    {
        $moduleModel = $this->relationModel->getRelationModuleModel();
        $parentModuleName = $this->relationModel->getParentModuleModel()->getName();
        $result = false;

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

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

Avoid using static access to class '\Vtiger_Record_Model' in method 'transfer'.
Open

            $recordModel = \Vtiger_Record_Model::getInstanceById($relatedRecordId, $this->relationModel->getRelationModuleName());

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

        } else {
            \App\Log::warning("Incorrectly deleted relationship: {$sourceRecordId},{$moduleModel->getName()},{$parentModuleName},{$destinationRecordId}");
        }

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 '\App\Condition' in method 'loadAdvancedConditionsByRelationId'.
Open

            $relationQueryGenerator->setConditions(\App\Condition::getConditionsFromRequest($advancedConditions['relationConditions']));

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_Record_Model' in method 'delete'.
Open

            $recordModel = \Vtiger_Record_Model::getInstanceById($destinationRecordId, $moduleModel);

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\Log' in method 'delete'.
Open

            \App\Log::warning("Incorrectly deleted relationship: {$sourceRecordId},{$moduleModel->getName()},{$parentModuleName},{$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

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

            $fieldModel->getTableName() . '.' . $this->relationModel->getQueryGenerator()->getEntityModel()->tab_name_index[$fieldModel->getTableName()] => $searchParam['value'],

Parameter $queryGenerator has undeclared type \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

    public function loadAdvancedConditionsByColumns(App\QueryGenerator $queryGenerator, array $searchParam): void

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

        $advancedConditions = $queryGenerator->getAdvancedConditions();

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

        $relationQueryGenerator->setStateCondition($queryGenerator->getState());

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

        $queryGenerator->addJoin(['INNER JOIN', $fieldModel->getTableName(), "vtiger_crmentity.crmid = {$fieldModel->getTableName()}.{$fieldModel->getColumnName()}"]);

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

        $queryGenerator->addNativeCondition([

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

        $query = $relationQueryGenerator->createQuery();

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

            $relationQueryGenerator->setConditions(\App\Condition::getConditionsFromRequest($advancedConditions['relationConditions']));

Call to method warning from undeclared class \App\Log
Open

            \App\Log::warning("Incorrectly deleted relationship: {$sourceRecordId},{$moduleModel->getName()},{$parentModuleName},{$destinationRecordId}");

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

            $fieldModel->getTableName() . '.' . $this->relationModel->getQueryGenerator()->getEntityModel()->tab_name_index[$fieldModel->getTableName()] => $query,

Suspicious type false of a variable or expression used to build a string. (Expected type to be able to cast to a string)
Open

            \App\Log::warning("Incorrectly deleted relationship: {$sourceRecordId},{$moduleModel->getName()},{$parentModuleName},{$destinationRecordId}");

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

        $queryGenerator->addNativeCondition([

Parameter $queryGenerator has undeclared type \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

    public function loadAdvancedConditionsByRelationId(App\QueryGenerator $queryGenerator): void

Argument 1 (moduleName) is false but \Vtiger_Module_Model::getReferenceFieldsForModule() takes string defined at /code/modules/Vtiger/models/Module.php:557
Open

        if ($fields = $moduleModel->getReferenceFieldsForModule($parentModuleName)) {

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

        $relationQueryGenerator->setStateCondition($queryGenerator->getState());

Argument 2 (module) is \Vtiger_Module_Model|\vtlib\Module|\vtlib\ModuleBasic but \Vtiger_Record_Model::getInstanceById() takes string defined at /code/modules/Vtiger/models/Record.php:763
Open

            $recordModel = \Vtiger_Record_Model::getInstanceById($destinationRecordId, $moduleModel);

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

        $relationQueryGenerator->setFields(['id']);

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

        $queryGenerator->addJoin(['INNER JOIN', $fieldModel->getTableName(), "vtiger_crmentity.crmid = {$fieldModel->getTableName()}.{$fieldModel->getColumnName()}"]);

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

        $queryGenerator->addTableToQuery($fieldModel->getTableName());

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

        $queryGenerator->addNativeCondition([

Avoid excessively long variable names like $relationQueryGenerator. Keep variable name length under 20.
Open

        $relationQueryGenerator = $this->relationModel->getQueryGenerator();

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

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

class Vtiger_GetDependentsList_Relation extends \App\Relation\RelationAbstraction

The class Vtiger_GetDependentsList_Relation is not named in CamelCase.
Open

class Vtiger_GetDependentsList_Relation extends \App\Relation\RelationAbstraction
{
    /** {@inheritdoc} */
    public function getRelationType(): int
    {

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

        $relationQueryGenerator->setStateCondition($queryGenerator->getState());

Line exceeds 120 characters; contains 163 characters
Open

            $fieldModel->getTableName() . '.' . $this->relationModel->getQueryGenerator()->getEntityModel()->tab_name_index[$fieldModel->getTableName()] => $query,

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

     * @param App\QueryGenerator $queryGenerator QueryGenerator for the list of records to be tapered based on the relationship

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 function transfer(int $relatedRecordId, int $fromRecordId, int $toRecordId): bool

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

        $relationFieldModel = $this->relationModel->getRelationField();

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 loadAdvancedConditionsByRelationId(App\QueryGenerator $queryGenerator): void

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

        $advancedConditions = $queryGenerator->getAdvancedConditions();

Line exceeds 120 characters; contains 127 characters
Open

     * @param App\QueryGenerator $queryGenerator QueryGenerator for the list of records to be tapered based on the relationship

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

        if ($fields = $moduleModel->getReferenceFieldsForModule($parentModuleName)) {

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

    /** {@inheritdoc} */

Line exceeds 120 characters; contains 131 characters
Open

            $fieldModel->getTableName() . '.' . $fieldModel->getColumnName() => $this->relationModel->get('parentRecord')->getId(),

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

        $fieldModel = $this->relationModel->getRelationField();

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

            $fieldModel->getTableName() . '.' . $this->relationModel->getQueryGenerator()->getEntityModel()->tab_name_index[$fieldModel->getTableName()] => $query,

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

                    $recordModel->set($fieldModel->getName(), 0);

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

    /** {@inheritdoc} */

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

    public function getQuery()

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

     * @param App\QueryGenerator $queryGenerator QueryGenerator for the list of records to be tapered based on the relationship

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

            \App\Log::warning("Incorrectly deleted relationship: {$sourceRecordId},{$moduleModel->getName()},{$parentModuleName},{$destinationRecordId}");

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 = \Vtiger_Record_Model::getInstanceById($relatedRecordId, $this->relationModel->getRelationModuleName());

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

        if (!empty($advancedConditions['relationConditions'])) {

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

        $parentModuleName = $this->relationModel->getParentModuleModel()->getName();

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

            foreach ($fields as $fieldModel) {

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

        return $result;

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

        if ($relationFieldModel && $relationFieldModel->isEditable()) {

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

    /** {@inheritdoc} */

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

        $query = $relationQueryGenerator->createQuery();

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 function create(int $sourceRecordId, int $destinationRecordId): bool

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

                $recordModel->ext['modificationType'] = \ModTracker_Record_Model::TRANSFER_EDIT;

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

        }

Line exceeds 120 characters; contains 167 characters
Open

        $queryGenerator->addJoin(['INNER JOIN', $fieldModel->getTableName(), "vtiger_crmentity.crmid = {$fieldModel->getTableName()}.{$fieldModel->getColumnName()}"]);

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

                    $result = true;

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

            $recordModel->save();

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

        } else {

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

                $recordModel->set($relationFieldModel->getName(), $toRecordId);

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

                $recordModel->save();

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

        $fieldModel = $this->relationModel->getRelationField();

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

        $result = false;

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

                $result = true;

Line exceeds 120 characters; contains 136 characters
Open

            $relationQueryGenerator->setConditions(\App\Condition::getConditionsFromRequest($advancedConditions['relationConditions']));

Line exceeds 120 characters; contains 167 characters
Open

        $queryGenerator->addJoin(['INNER JOIN', $fieldModel->getTableName(), "vtiger_crmentity.crmid = {$fieldModel->getTableName()}.{$fieldModel->getColumnName()}"]);

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

     *

Line exceeds 120 characters; contains 178 characters
Open

            $fieldModel->getTableName() . '.' . $this->relationModel->getQueryGenerator()->getEntityModel()->tab_name_index[$fieldModel->getTableName()] => $searchParam['value'],

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

        ]);

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

        $queryGenerator = $this->relationModel->getQueryGenerator();

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

        $queryGenerator->addNativeCondition([

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

     * Load advanced conditions for filtering related records.

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

     *

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

        $relationQueryGenerator = $this->relationModel->getQueryGenerator();

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

        $queryGenerator->addNativeCondition([

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

    }

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

     * Load advanced conditions relationship by custom column.

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

    /** {@inheritdoc} */

Line exceeds 120 characters; contains 127 characters
Open

     * @param App\QueryGenerator $queryGenerator QueryGenerator for the list of records to be tapered based on the relationship

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

            $relationQueryGenerator->setConditions(\App\Condition::getConditionsFromRequest($advancedConditions['relationConditions']));

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

            }

Line exceeds 120 characters; contains 154 characters
Open

            \App\Log::warning("Incorrectly deleted relationship: {$sourceRecordId},{$moduleModel->getName()},{$parentModuleName},{$destinationRecordId}");

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 true;

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

        $queryGenerator->addTableToQuery($fieldModel->getTableName());

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

        $relationQueryGenerator->setFields(['id']);

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

        $queryGenerator->addJoin(['INNER JOIN', $fieldModel->getTableName(), "vtiger_crmentity.crmid = {$fieldModel->getTableName()}.{$fieldModel->getColumnName()}"]);

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

    public function loadAdvancedConditionsByColumns(App\QueryGenerator $queryGenerator, array $searchParam): void

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

        $queryGenerator->addJoin(['INNER JOIN', $fieldModel->getTableName(), "vtiger_crmentity.crmid = {$fieldModel->getTableName()}.{$fieldModel->getColumnName()}"]);

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

    public function delete(int $sourceRecordId, int $destinationRecordId): bool

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

        $moduleModel = $this->relationModel->getRelationModuleModel();

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

                if ((int) $recordModel->get($fieldModel->getName()) === (int) $sourceRecordId) {

Line exceeds 120 characters; contains 130 characters
Open

            $recordModel = \Vtiger_Record_Model::getInstanceById($relatedRecordId, $this->relationModel->getRelationModuleName());

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

    /**

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->getTableName() . '.' . $this->relationModel->getQueryGenerator()->getEntityModel()->tab_name_index[$fieldModel->getTableName()] => $searchParam['value'],

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

    /** {@inheritdoc} */

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 = $this->relationModel->getRelationField();

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 $result;

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

        ]);

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

        $queryGenerator->addNativeCondition([

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

        $result = false;

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

            $recordModel = \Vtiger_Record_Model::getInstanceById($destinationRecordId, $moduleModel);

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 getRelationType(): int

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

        return Vtiger_Relation_Model::RELATION_O2M;

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->getTableName() . '.' . $fieldModel->getColumnName() => $this->relationModel->get('parentRecord')->getId(),

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

    {

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

     * @param array              $searchParam    Related record for which we are filtering the list of records

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 ($recordModel->isEditable() && $recordModel->get($relationFieldModel->getName()) === $fromRecordId) {

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

class Vtiger_GetDependentsList_Relation extends \App\Relation\RelationAbstraction

There are no issues that match your filters.

Category
Status