YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/models/RelatedCommentModal.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

Missing class import via use statement (line '48', column '15').
Open

        return (new \App\Db\Query())->select(['rel_comment'])

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

        return (new \App\Db\Query())->select(['rel_comment'])

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

Avoid assigning values to variables in if clauses and the like (line '37', column '7').
Open

    public function getComment()
    {
        if ('T' === substr($this->get('relatedRecord'), 0, 1)) {
            $dataReader = $this->getRelationTreeQuery()->createCommand()->query();
        } else {

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

The method save uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $relationTable = $this->getRelationTable();
            $table = key($relationTable);
            $db->createCommand()->update($table, [
                'rel_comment' => $comment,

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\Db' in method 'save'.
Open

        $db = App\Db::getInstance();

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_Loader' in method 'getInstance'.
Open

        $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'RelatedCommentModal', $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 'getRelationTreeQuery'.
Open

            ->where(['crmid' => $this->get('record'), 'tree' => $this->get('relatedRecord'), 'relmodule' => App\Module::getModuleId($this->get('relatedModuleName'))]);

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

        $recordModel = Vtiger_Record_Model::getInstanceById($record, $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 'Vtiger_RelationListView_Model' in method 'getInstance'.
Open

        $relationListView = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);

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

        } else {
            $dataReader = $this->getRelationQuery()->createCommand()->query();
        }

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 'CRMEntity' in method 'getRelationTable'.
Open

        $instance = CRMEntity::getInstance($this->get('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 'save'.
Open

            ], ['crmid' => $this->get('record'), 'tree' => $this->get('relatedRecord'), 'relmodule' => App\Module::getModuleId($this->get('relatedModuleName'))]

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 "rel_comment" 4 times.
Open

        return (new \App\Db\Query())->select(['rel_comment'])

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" 3 times.
Open

            $relationTable = ['vtiger_crmentityrel' => ['crmid', 'relcrmid'], $instance->table_name => $instance->table_index];

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 "relatedModuleName" 4 times.
Open

            ->set('relatedModuleName', $relatedModuleName);

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 "record" 5 times.
Open

            ->set('record', $record)

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 "relatedRecord" 7 times.
Open

            ->set('relatedRecord', $relatedRecord)

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 undeclared method \App\Db\Query::select
Open

        return (new \App\Db\Query())->select(['rel_comment'])

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

            $db->createCommand()->update('u_#__crmentity_rel_tree', [

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

            $db->createCommand()->update($table, [

Reference to undeclared property \CRMEntity->table_index
Open

            $relationTable = ['vtiger_crmentityrel' => ['crmid', 'relcrmid'], $instance->table_name => $instance->table_index];

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

        return (new \App\Db\Query())->select(['rel_comment'])

Reference to undeclared property \CRMEntity->table_name
Open

            $relationTable = ['vtiger_crmentityrel' => ['crmid', 'relcrmid'], $instance->table_name => $instance->table_index];

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

class Vtiger_RelatedCommentModal_Model extends \App\Base

The class Vtiger_RelatedCommentModal_Model is not named in CamelCase.
Open

class Vtiger_RelatedCommentModal_Model extends \App\Base
{
    public static function getInstance($record, $moduleName, $relatedRecord, $relatedModuleName)
    {
        $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'RelatedCommentModal', $moduleName);

CamelCaseClassName

Since: 0.2

It is considered best practice to use the CamelCase notation to name classes.

Example

class class_name {
}

Source

Avoid variables with short names like $db. Configured minimum length is 3.
Open

        $db = App\Db::getInstance();

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

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

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 static function getInstance($record, $moduleName, $relatedRecord, $relatedModuleName)

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

        return $instance;

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

            $dataReader = $this->getRelationTreeQuery()->createCommand()->query();

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

        $instance = new $modelClassName();

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

        if ($result = $dataReader->readColumn(0)) {

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

    public function getComment()

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

        $recordModel = Vtiger_Record_Model::getInstanceById($record, $moduleName);

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

    {

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

        $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'RelatedCommentModal', $moduleName);

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

    public function getRelationQuery()

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

        $instance->set('relationListView', $relationListView)

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

            $dataReader = $this->getRelationQuery()->createCommand()->query();

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

            ->set('relatedModuleName', $relatedModuleName);

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

        $relationListView = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);

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

            ->set('record', $record)

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

        return '';

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

    }

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

            ->set('moduleName', $moduleName)

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

        if ('T' === substr($this->get('relatedRecord'), 0, 1)) {

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

            ->set('relatedRecord', $relatedRecord)

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

            ], ['crmid' => $this->get('record'), 'tree' => $this->get('relatedRecord'), 'relmodule' => App\Module::getModuleId($this->get('relatedModuleName'))]

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

        } else {

Line exceeds 120 characters; contains 127 characters
Open

            $relationTable = ['vtiger_crmentityrel' => ['crmid', 'relcrmid'], $instance->table_name => $instance->table_index];

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

    public function getRelationTable()

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

        return (new \App\Db\Query())->select(['rel_comment'])

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

                'rel_comment' => $comment,

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 ('T' === substr($this->get('relatedRecord'), 0, 1)) {

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

            $db->createCommand()->update('u_#__crmentity_rel_tree', [

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

            $relationTable = ['vtiger_crmentityrel' => ['crmid', 'relcrmid'], $instance->table_name => $instance->table_index];

Line exceeds 120 characters; contains 131 characters
Open

            ->where([$relationTable[$table][0] => $this->get('record'), $relationTable[$table][1] => $this->get('relatedRecord')]);

Line exceeds 120 characters; contains 160 characters
Open

            ], ['crmid' => $this->get('record'), 'tree' => $this->get('relatedRecord'), 'relmodule' => App\Module::getModuleId($this->get('relatedModuleName'))]

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

        return $relationTable;

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 isEditable(): bool

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

            $db->createCommand()->update($table, [

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

        if (method_exists($instance, 'setRelationTables')) {

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

            $relationTable = $instance->setRelationTables($this->get('relatedModuleName'));

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

            ->from('u_#__crmentity_rel_tree')

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 save($comment)

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

            ], [$relationTable[$table][0] => $this->get('record'), $relationTable[$table][1] => $this->get('relatedRecord')]

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

        $table = key($relationTable);

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

        }

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

        $instance = CRMEntity::getInstance($this->get('moduleName'));

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

        return $this->get('relationListView')->getRelationModel()->get('relation_comment');

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

        return (new \App\Db\Query())->select(['rel_comment'])

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

            ->where([$relationTable[$table][0] => $this->get('record'), $relationTable[$table][1] => $this->get('relatedRecord')]);

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

        if (empty($relationTable)) {

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

            $table = key($relationTable);

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

        $relationTable = $this->getRelationTable();

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

                'rel_comment' => $comment,

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

    }

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

            ->from($table)

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

    public function getRelationTreeQuery()

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

            ->where(['crmid' => $this->get('record'), 'tree' => $this->get('relatedRecord'), 'relmodule' => App\Module::getModuleId($this->get('relatedModuleName'))]);

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

    {

Line exceeds 120 characters; contains 167 characters
Open

            ->where(['crmid' => $this->get('record'), 'tree' => $this->get('relatedRecord'), 'relmodule' => App\Module::getModuleId($this->get('relatedModuleName'))]);

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

    {

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

        $db = App\Db::getInstance();

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

            $relationTable = $this->getRelationTable();

Line exceeds 120 characters; contains 124 characters
Open

            ], [$relationTable[$table][0] => $this->get('record'), $relationTable[$table][1] => $this->get('relatedRecord')]

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

class Vtiger_RelatedCommentModal_Model extends \App\Base

Expected 0 spaces before closing bracket; newline found
Open

            $db->createCommand()->update('u_#__crmentity_rel_tree', [

Expected 0 spaces before closing bracket; newline found
Open

            $db->createCommand()->update($table, [

There are no issues that match your filters.

Category
Status