YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/QuickCreateEditor/models/Module.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

Avoid using undefined variables such as '$fieldIdList' which will lead to PHP notices.
Open

                $fieldIdList[] = $newFieldSequence['fieldid'];

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$fieldIdList' which will lead to PHP notices.
Open

            $result = $db->createCommand()->update('vtiger_field', ['quickcreatesequence' => new \yii\db\Expression($caseExpression)], ['fieldid' => $fieldIdList])->execute();

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Missing class import via use statement (line '29', column '89').
Open

            $result = $db->createCommand()->update('vtiger_field', ['quickcreatesequence' => new \yii\db\Expression($caseExpression)], ['fieldid' => $fieldIdList])->execute();

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 using static access to class '\App\Db' in method 'updateFieldSequenceNumber'.
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 '\App\Field' in method 'updateFieldSequenceNumber'.
Open

                $fieldInfo = \App\Field::getFieldInfo($newFieldSequence['fieldid']);

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\Cache' in method 'updateFieldSequenceNumber'.
Open

                \App\Cache::delete('AllFieldForModule', $fieldInfo['tabid']);

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

                $caseExpression .= " WHEN fieldid = {$db->quoteValue($newFieldSequence['fieldid'])} THEN {$db->quoteValue($newFieldSequence['sequence'])}";

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 __construct from undeclared class \yii\db\Expression
Open

            $result = $db->createCommand()->update('vtiger_field', ['quickcreatesequence' => new \yii\db\Expression($caseExpression)], ['fieldid' => $fieldIdList])->execute();

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

                $caseExpression .= " WHEN fieldid = {$db->quoteValue($newFieldSequence['fieldid'])} THEN {$db->quoteValue($newFieldSequence['sequence'])}";

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

            $result = $db->createCommand()->update('vtiger_field', ['quickcreatesequence' => new \yii\db\Expression($caseExpression)], ['fieldid' => $fieldIdList])->execute();

Variable $fieldIdList was undeclared, but array fields are being added to it.
Open

                $fieldIdList[] = $newFieldSequence['fieldid'];

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

class Settings_QuickCreateEditor_Module_Model extends Vtiger_Module_Model

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

The class Settings_QuickCreateEditor_Module_Model is not named in CamelCase.
Open

class Settings_QuickCreateEditor_Module_Model extends Vtiger_Module_Model
{
    /**
     * Update sequence number for quickcreate.
     *

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

            $result = $db->createCommand()->update('vtiger_field', ['quickcreatesequence' => new \yii\db\Expression($caseExpression)], ['fieldid' => $fieldIdList])->execute();

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

            }

Line exceeds 120 characters; contains 155 characters
Open

                $caseExpression .= " WHEN fieldid = {$db->quoteValue($newFieldSequence['fieldid'])} THEN {$db->quoteValue($newFieldSequence['sequence'])}";

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

            $caseExpression .= ' END';

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

            foreach ($blockFieldSequence as $newFieldSequence) {

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

                $fieldIdList[] = $newFieldSequence['fieldid'];

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

    /**

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

                $caseExpression .= " WHEN fieldid = {$db->quoteValue($newFieldSequence['fieldid'])} THEN {$db->quoteValue($newFieldSequence['sequence'])}";

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

            $caseExpression = 'CASE';

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

                \App\Cache::delete('AllFieldForModule', $fieldInfo['tabid']);

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

                $fieldInfo = \App\Field::getFieldInfo($newFieldSequence['fieldid']);

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

     * Update sequence number for quickcreate.

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 int

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

    public static function updateFieldSequenceNumber($blockFieldSequence)

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 = 0;

Line exceeds 120 characters; contains 175 characters
Open

            $result = $db->createCommand()->update('vtiger_field', ['quickcreatesequence' => new \yii\db\Expression($caseExpression)], ['fieldid' => $fieldIdList])->execute();

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

     * @param array $blockFieldSequence

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 ($blockFieldSequence) {

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

        }

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

class Settings_QuickCreateEditor_Module_Model extends Vtiger_Module_Model

There are no issues that match your filters.

Category
Status