YetiForceCompany/YetiForceCRM

View on GitHub
modules/ModComments/relations/GetRelatedRecord.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/ModComments/relations/GetRelatedRecord.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 '50', 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 '69', column '21').
Open

            $subQuery = (new \App\QueryGenerator('ModComments'))->setFields(['id'])->setSourceRecord($parentId)->createQuery()->select((new \yii\db\Expression('COUNT(1)')))->andWhere(['parent_comments' => new yii\db\Expression('id')])->groupBy(['parent_comments']);

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 '69', column '132').
Open

            $subQuery = (new \App\QueryGenerator('ModComments'))->setFields(['id'])->setSourceRecord($parentId)->createQuery()->select((new \yii\db\Expression('COUNT(1)')))->andWhere(['parent_comments' => new yii\db\Expression('id')])->groupBy(['parent_comments']);

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

Missing class import via use statement (line '69', column '201').
Open

            $subQuery = (new \App\QueryGenerator('ModComments'))->setFields(['id'])->setSourceRecord($parentId)->createQuery()->select((new \yii\db\Expression('COUNT(1)')))->andWhere(['parent_comments' => new yii\db\Expression('id')])->groupBy(['parent_comments']);

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

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

            $subQuery = (new \App\QueryGenerator('ModComments'))->setFields(['id'])->setSourceRecord($parentId)->createQuery()->select((new \yii\db\Expression('COUNT(1)')))->andWhere(['parent_comments' => new yii\db\Expression('id')])->groupBy(['parent_comments']);

Call to method __construct from undeclared class \yii\db\Expression
Open

            $subQuery = (new \App\QueryGenerator('ModComments'))->setFields(['id'])->setSourceRecord($parentId)->createQuery()->select((new \yii\db\Expression('COUNT(1)')))->andWhere(['parent_comments' => new yii\db\Expression('id')])->groupBy(['parent_comments']);

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

        $queryGenerator->addCondition('related_to', $parentId, 'eid');

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

            $queryGenerator->setCustomColumn([$fieldName => $subQuery]);

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

            $subQuery = (new \App\QueryGenerator('ModComments'))->setFields(['id'])->setSourceRecord($parentId)->createQuery()->select((new \yii\db\Expression('COUNT(1)')))->andWhere(['parent_comments' => new yii\db\Expression('id')])->groupBy(['parent_comments']);

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

class ModComments_GetRelatedRecord_Relation extends \App\Relation\RelationAbstraction

The class ModComments_GetRelatedRecord_Relation is not named in CamelCase.
Open

class ModComments_GetRelatedRecord_Relation extends \App\Relation\RelationAbstraction
{
    /**
     * Field custom list.
     *

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

            $subQuery = (new \App\QueryGenerator('ModComments'))->setFields(['id'])->setSourceRecord($parentId)->createQuery()->select((new \yii\db\Expression('COUNT(1)')))->andWhere(['parent_comments' => new yii\db\Expression('id')])->groupBy(['parent_comments']);

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

        return false;

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

        ],

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

            $queryGenerator->setCustomColumn([$fieldName => $subQuery]);

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

            }

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

        $parentId = $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

    public function getFields(bool $editable = false)

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

    }

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

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

        return false;

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 $customFields = [

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

            'uitype' => 7,

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

        }

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

        return false;

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

        foreach ($this->customFields as $fieldName => $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

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

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

        }

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

    {

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

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

            'label' => 'LBL_CHILDREN_COUNT',

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

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

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 265 characters
Open

            $subQuery = (new \App\QueryGenerator('ModComments'))->setFields(['id'])->setSourceRecord($parentId)->createQuery()->select((new \yii\db\Expression('COUNT(1)')))->andWhere(['parent_comments' => new yii\db\Expression('id')])->groupBy(['parent_comments']);

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

        'children_count' => [

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

     * @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

    }

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

    public function getRelationType(): int

Line exceeds 120 characters; contains 163 characters
Open

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

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

        $queryGenerator->addCondition('related_to', $parentId, 'eid');

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

                $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

        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

     * @var 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

    /** {@inheritdoc} */

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

     * @return array

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

            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

    /** {@inheritdoc} */

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

class ModComments_GetRelatedRecord_Relation extends \App\Relation\RelationAbstraction

There are no issues that match your filters.

Category
Status