YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/SharingAccess/models/Action.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

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

        $query = (new App\Db\Query())->from('vtiger_org_share_action_mapping');

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 getAll has a boolean flag argument $configurable, which is a certain sign of a Single Responsibility Principle violation.
Open

    public static function getAll($configurable = true)

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

        return (new \App\Db\Query())->from('vtiger_org_share_action2tab')

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 '47', column '17').
Open

        $query = (new App\Db\Query())->from('vtiger_org_share_action_mapping');

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 'vtlib\Utils' in method 'getInstance'.
Open

        if (vtlib\Utils::isNumber($value)) {

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

        } else {
            $query->where(['share_action_name' => $value]);
        }

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

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

        return $this->get('share_action_name');

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

        return $this->get('share_action_id');

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::from
Open

        $query = (new App\Db\Query())->from('vtiger_org_share_action_mapping');

Return type of getInstance() is undeclared type \self
Open

    public static function getInstance($value)

Returning type null but getInstance() is declared to return \Settings_SharingAccess_Action_Model|\self
Open

        return null;

Return type of getAll() is undeclared type \self[]
Open

    public static function getAll($configurable = true)

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

        return (new \App\Db\Query())->from('vtiger_org_share_action2tab')

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

        $query = (new App\Db\Query())->from('vtiger_org_share_action_mapping');

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

    public static $nonConfigurableActions = ['Hide Details', 'Hide Details and Add Events', 'Show Details', 'Show Details and Add Events'];

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 Settings_SharingAccess_Action_Model extends \App\Base

The class Settings_SharingAccess_Action_Model is not named in CamelCase.
Open

class Settings_SharingAccess_Action_Model extends \App\Base
{
    public static $nonConfigurableActions = ['Hide Details', 'Hide Details and Add Events', 'Show Details', 'Show Details and Add Events'];

    public function getId()

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

    public function getName()

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

            ->exists();

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

    public static function getAll($configurable = true)

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

            $actionModel = new self();

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 $this->get('share_action_name');

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

    public function isModuleEnabled($module)

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

        }

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

        while ($row = $dataReader->read()) {

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

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

        $dataReader->close();

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

        return $this->get('share_action_id');

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

            ->where(['tabid' => $module->getId(), 'share_action_id' => $this->getId()])

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

        if (vtlib\Utils::isNumber($value)) {

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

     * @param bool $configurable

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 isUtilityTool()

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 self())->setData($result);

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

        return $actionModels;

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

     * @param int|string $value

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

     * @return \self[]

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 = (new App\Db\Query())->from('vtiger_org_share_action_mapping');

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

            $query->where(['NOT IN', 'share_action_name', self::$nonConfigurableActions]);

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

        $actionModels = [];

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

            $actionModel->setData($row);

Line exceeds 120 characters; contains 139 characters
Open

    public static $nonConfigurableActions = ['Hide Details', 'Hide Details and Add Events', 'Show Details', 'Show Details and Add Events'];

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

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

    public static function getInstance($value)

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

            $query->where(['share_action_name' => $value]);

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

        $result = $query->one();

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

    }

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

     * Function to get all action.

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

            $query->where(['share_action_id' => $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

        return null;

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

        return (new \App\Db\Query())->from('vtiger_org_share_action2tab')

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

     * Function to get instance of class.

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 = (new App\Db\Query())->from('vtiger_org_share_action_mapping');

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 $nonConfigurableActions = ['Hide Details', 'Hide Details and Add Events', 'Show Details', 'Show Details and Add Events'];

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

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

    {

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

     */

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

        $dataReader = $query->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

     */

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

            $actionModels[] = $actionModel;

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

class Settings_SharingAccess_Action_Model extends \App\Base

There are no issues that match your filters.

Category
Status