YetiForceCompany/YetiForceCRM

View on GitHub
modules/Occurrences/relations/GetRelatedMembers.php

Summary

Maintainability
A
35 mins
Test Coverage
F
0%

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

    public function getFields(bool $editable = false)
    {
        $fields = [];
        $sourceModule = $this->relationModel->getParentModuleModel();
        if ('Occurrences' !== $sourceModule->getName()) {
Severity: Minor
Found in modules/Occurrences/relations/GetRelatedMembers.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

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

            $field = new \Vtiger_Field_Model();

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 '126', column '15').
Open

        return (new \App\Db\Query())->from(static::TABLE_NAME)->where([

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

The method getFields has a boolean flag argument $editable, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function getFields(bool $editable = false)

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

Avoid using static access to class '\App\User' in method 'create'.
Open

                'rel_created_user' => \App\User::getCurrentUserRealId(),

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

Define a constant instead of duplicating this literal "uitype" 3 times.
Open

            'uitype' => 16,

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Define a constant instead of duplicating this literal "crmid" 5 times.
Open

                'crmid' => $sourceRecordId,

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Define a constant instead of duplicating this literal "label" 3 times.
Open

            'label' => 'LBL_STATUS_REL',

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Define a constant instead of duplicating this literal "relcrmid" 5 times.
Open

                'relcrmid' => $destinationRecordId,

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Call to method getCurrentUserRealId from undeclared class \App\User (Did you mean class \Tests\App\User)
Open

                'rel_created_user' => \App\User::getCurrentUserRealId(),

Call to undeclared method \App\Db\Query::from
Open

        return (new \App\Db\Query())->from(static::TABLE_NAME)->where([

Call to undeclared method \App\Db::createCommand
Open

            $result = (bool) \App\Db::getInstance()->createCommand()->update(static::TABLE_NAME, $updateData, $conditions)->execute();

Call to undeclared method \App\Db::createCommand
Open

            $result = \App\Db::getInstance()->createCommand()->insert(static::TABLE_NAME, [

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

            $queryGenerator->setCustomColumn(["{$tableName}.{$fieldName}"]);

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

class Occurrences_GetRelatedMembers_Relation extends Vtiger_GetRelatedList_Relation

The class Occurrences_GetRelatedMembers_Relation is not named in CamelCase.
Open

class Occurrences_GetRelatedMembers_Relation extends Vtiger_GetRelatedList_Relation
{
    /** {@inheritdoc} */
    public const TABLE_NAME = 'u_#__relations_members_entity';

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

    ];

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

        foreach ($this->customFields as $fieldName => $data) {

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

        $tableName = static::TABLE_NAME;

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

        foreach (array_keys($this->customFields) as $fieldName) {

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

    {

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

            ])->execute();

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

     * @return array

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

            foreach ($data as $key => $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

    }

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

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

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

            if (!$editable || !$field->isEditableReadOnly()) {

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

        $result = false;

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

                'relcrmid' => $destinationRecordId,

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

     * @param array $updateData

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

        return $result;

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

            'or',

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

     * @param int $destinationRecordId

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

            'label' => 'LBL_RELATION_CREATED_USER',

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

     * @return array

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

    }

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

            $result = (bool) \App\Db::getInstance()->createCommand()->update(static::TABLE_NAME, $updateData, $conditions)->execute();

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} */

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

    public $customFields = [

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

        ],

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

        'comment_rel' => [

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

        $fields = [];

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

        }

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

                $fields[$fieldName] = $field;

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

        parent::getQuery();

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

            $queryGenerator->setCustomColumn(["{$tableName}.{$fieldName}"]);

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

                'crmid' => $sourceRecordId,

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

        $conditions = [

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

        $result = (bool) $this->getRelationData($sourceRecordId, $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

    /**

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 const TABLE_NAME = 'u_#__relations_members_entity';

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

            'uitype' => 21,

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

     * Field list.

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

     * @param bool $editable

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

     * @param int   $destinationRecordId

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

     * @param int $sourceRecordId

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

    public function getRelationData(int $sourceRecordId, int $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

        $sourceModule = $this->relationModel->getParentModuleModel();

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

    {

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

            ['crmid' => $destinationRecordId, 'relcrmid' => $sourceRecordId],

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

    }

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

            'displaytype' => 10

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

    public function getFields(bool $editable = false)

Line exceeds 120 characters; contains 161 characters
Open

            $field->set('name', $fieldName)->set('column', $fieldName)->set('table', static::TABLE_NAME)->set('fromOutsideList', true)->setModule($sourceModule);

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

    public function updateRelationData(int $sourceRecordId, int $destinationRecordId, array $updateData): bool

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

     * @var array

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

                $field->set($key, $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

     *

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

        if ($result) {

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

     * Get relation data.

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

            $field = new \Vtiger_Field_Model();

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 (!$this->getRelationData($sourceRecordId, $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

     *

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

     * @return bool

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

            'maximumlength' => 65535

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

        'status_rel' => [

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

        ],

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

            'uitype' => 52,

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

     * updateRelationData function.

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

     * @param int   $sourceRecordId

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

            ['crmid' => $sourceRecordId, 'relcrmid' => $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 (new \App\Db\Query())->from(static::TABLE_NAME)->where([

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

            'or',

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

            ['crmid' => $sourceRecordId, 'relcrmid' => $destinationRecordId],

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

     * Field custom list.

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

            'label' => 'LBL_STATUS_REL',

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

        'rel_created_user' => [

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

        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

     *

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

            'uitype' => 16,

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

            'label' => 'LBL_COMMENT_REL',

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

     */

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

            ['crmid' => $destinationRecordId, 'relcrmid' => $sourceRecordId],

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

        ])->one();

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

        return $fields;

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

            $result = \App\Db::getInstance()->createCommand()->insert(static::TABLE_NAME, [

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

    /**

Line exceeds 120 characters; contains 134 characters
Open

            $result = (bool) \App\Db::getInstance()->createCommand()->update(static::TABLE_NAME, $updateData, $conditions)->execute();

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 ('Occurrences' !== $sourceModule->getName()) {

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

            $field->set('name', $fieldName)->set('column', $fieldName)->set('table', static::TABLE_NAME)->set('fromOutsideList', true)->setModule($sourceModule);

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

                'rel_created_user' => \App\User::getCurrentUserRealId(),

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

    }

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

class Occurrences_GetRelatedMembers_Relation extends Vtiger_GetRelatedList_Relation

There are no issues that match your filters.

Category
Status