YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

Function getOpenTicketStatus has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public static function getOpenTicketStatus()
    {
        $getTicketStatusClosed = self::getTicketStatusNotModify();
        \App\Log::trace(__METHOD__);
        if (empty($getTicketStatusClosed)) {
Severity: Minor
Found in modules/Settings/SupportProcesses/models/Module.php - About 1 hr 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 '42', column '24').
Open

        $ticketStatus = (new App\Db\Query())->select(['ticket_status_indicate_closing'])

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\Log' in method 'updateTicketStatusNotModify'.
Open

        \App\Log::trace('Entering Settings_SupportProcesses_Module_Model::updateTicketStatusNotModify() method ...');

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\Fields\Picklist' in method 'getAllTicketStatus'.
Open

        return App\Fields\Picklist::getValuesName('ticketstatus');

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\Log' in method 'getTicketStatus'.
Open

        \App\Log::trace('Exiting Settings_SupportProcesses_Module_Model::getTicketStatus() method ...');

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\Log' in method 'getAllTicketStatus'.
Open

        \App\Log::trace(__METHOD__);

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\Log' in method 'updateTicketStatusNotModify'.
Open

        \App\Log::trace('Exiting Settings_SupportProcesses_Module_Model::updateTicketStatusNotModify() method ...');

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\Log' in method 'getOpenTicketStatus'.
Open

        \App\Log::trace(__METHOD__);

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\Fields\Picklist' in method 'getTicketStatus'.
Open

        $return = App\Fields\Picklist::getValuesName('ticketstatus');

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

        } else {
            $getAllTicketStatus = self::getAllTicketStatus();
            foreach ($getTicketStatusClosed as $key => $closedStatus) {
                foreach ($getAllTicketStatus as $key => $status) {
                    if ($closedStatus == $status) {

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\Log' in method 'getTicketStatus'.
Open

        \App\Log::trace('Entering Settings_SupportProcesses_Module_Model::getTicketStatus() method ...');

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

            ->from('vtiger_support_processes')

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

        $ticketStatus = (new App\Db\Query())->select(['ticket_status_indicate_closing'])

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

        $ticketStatus = (new App\Db\Query())->select(['ticket_status_indicate_closing'])

Call to method trace from undeclared class \App\Log
Open

        \App\Log::trace(__METHOD__);

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

        \App\Db::getInstance()->createCommand()->update('vtiger_support_processes', [

Call to method trace from undeclared class \App\Log
Open

        \App\Log::trace('Entering Settings_SupportProcesses_Module_Model::updateTicketStatusNotModify() method ...');

Call to method trace from undeclared class \App\Log
Open

        \App\Log::trace('Entering Settings_SupportProcesses_Module_Model::getTicketStatus() method ...');

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

            \App\Db::getInstance()->createCommand()->update('vtiger_support_processes', [

Call to method trace from undeclared class \App\Log
Open

        \App\Log::trace('Exiting Settings_SupportProcesses_Module_Model::getTicketStatus() method ...');

Call to method trace from undeclared class \App\Log
Open

        \App\Log::trace('Exiting Settings_SupportProcesses_Module_Model::updateTicketStatusNotModify() method ...');

Call to method trace from undeclared class \App\Log
Open

        \App\Log::trace(__METHOD__);

Returning type true but updateTicketStatusNotModify() is declared to return array
Open

        return true;

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

    protected static $ticketStatusNotModify;

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

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

        $getTicketStatusClosed = self::getTicketStatusNotModify();

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_SupportProcesses_Module_Model extends Settings_Vtiger_Module_Model

The class Settings_SupportProcesses_Module_Model is not named in CamelCase.
Open

class Settings_SupportProcesses_Module_Model extends Settings_Vtiger_Module_Model
{
    public static function getCleanInstance()
    {
        return new self();

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

        ], ['id' => 1])->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

    public static function getTicketStatusNotModify()

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 = $getAllTicketStatus;

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

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

        \App\Log::trace('Exiting Settings_SupportProcesses_Module_Model::getTicketStatus() method ...');

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

     * Update ticket status for support processes from support_processes.

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

            \App\Db::getInstance()->createCommand()->update('vtiger_support_processes', [

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

            foreach ($getTicketStatusClosed as $key => $closedStatus) {

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

        \App\Log::trace('Entering Settings_SupportProcesses_Module_Model::updateTicketStatusNotModify() method ...');

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

            ], ['id' => 1])->execute();

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

            $getAllTicketStatus = self::getAllTicketStatus();

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

        return 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 = App\Fields\Picklist::getValuesName('ticketstatus');

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

        if (self::$ticketStatusNotModify) {

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

        if (empty($getTicketStatusClosed)) {

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

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

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

        $getTicketStatusClosed = self::getTicketStatusNotModify();

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

        \App\Log::trace(__METHOD__);

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 $return;

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

        $ticketStatus = (new App\Db\Query())->select(['ticket_status_indicate_closing'])

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 array - array of ticket status

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

                    if ($closedStatus == $status) {

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

    {

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

        self::$ticketStatusNotModify = $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

    public function updateTicketStatusNotModify($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

        return App\Fields\Picklist::getValuesName('ticketstatus');

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

     */

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

        if (!empty($ticketStatus)) {

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

        }

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

        \App\Db::getInstance()->createCommand()->update('vtiger_support_processes', [

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

        if (!empty($data['val'])) {

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

        \App\Log::trace('Exiting Settings_SupportProcesses_Module_Model::updateTicketStatusNotModify() method ...');

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

    }

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

     * Gets ticket status for support processes from support_processes.

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

     * Gets ticket status for support processes.

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

        \App\Log::trace('Entering Settings_SupportProcesses_Module_Model::getTicketStatus() method ...');

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

            return self::$ticketStatusNotModify;

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

            ->scalar();

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

        \App\Log::trace(__METHOD__);

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

    public static function getOpenTicketStatus()

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 = explode(',', $ticketStatus);

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

     *

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

            'ticket_status_indicate_closing' => '',

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

            $data = implode(',', \is_array($data['val']) ? $data['val'] : [$data['val']]);

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

                foreach ($getAllTicketStatus as $key => $status) {

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

                        unset($getAllTicketStatus[$key]);

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

        }

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

    protected static $ticketStatusNotModify;

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

     * @return array - array of ticket status

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

                'ticket_status_indicate_closing' => $data,

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

    public static function getAllTicketStatus()

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

    /**

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

     * @return array - array of ticket status

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

            ->from('vtiger_support_processes')

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

     * @param mixed $data

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

class Settings_SupportProcesses_Module_Model extends Settings_Vtiger_Module_Model

There are no issues that match your filters.

Category
Status