YetiForceCompany/YetiForceCRM

View on GitHub
modules/Queue/handlers/Queue.php

Summary

Maintainability
A
1 hr
Test Coverage
F
45%

Function updateData has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    public static function updateData(int $recordId)
    {
        $recordModel = \Vtiger_Record_Model::getInstanceById($recordId, 'Queue');
        $data = \App\Json::decode($recordModel->get('changes')) ?: [];
        if ($data) {
Severity: Minor
Found in modules/Queue/handlers/Queue.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

Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.
Open

    public static function updateData(int $recordId)
Severity: Critical
Found in modules/Queue/handlers/Queue.php by sonar-php

Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

See

Missing class import via use statement (line '26', column '9').
Open

            (new \App\BatchMethod(['method' => 'Queue_Queue_Handler::updateData', 'params' => [$recordModel->getId()]]))->save();
Severity: Minor
Found in modules/Queue/handlers/Queue.php by phpmd

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 '\Vtiger_Record_Model' in method 'updateData'.
Open

        $recordModel = \Vtiger_Record_Model::getInstanceById($recordId, 'Queue');
Severity: Minor
Found in modules/Queue/handlers/Queue.php by phpmd

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\Record' in method 'updateData'.
Open

            if (\App\Record::isExists($relatedRecordId, $relatedModule)) {
Severity: Minor
Found in modules/Queue/handlers/Queue.php by phpmd

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\Json' in method 'updateData'.
Open

        $data = \App\Json::decode($recordModel->get('changes')) ?: [];
Severity: Minor
Found in modules/Queue/handlers/Queue.php by phpmd

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

                $relatedRecordModel = \Vtiger_Record_Model::getInstanceById($relatedRecordId, $relatedModule);
Severity: Minor
Found in modules/Queue/handlers/Queue.php by phpmd

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

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

class Queue_Queue_Handler

The class Queue_Queue_Handler is not named in CamelCase.
Open

class Queue_Queue_Handler
{
    /**
     * EntityAfterSave handler function.
     *
Severity: Minor
Found in modules/Queue/handlers/Queue.php by phpmd

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

        if ('PLL_ACCEPTED' === $recordModel->get('queue_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

        $recordModel = \Vtiger_Record_Model::getInstanceById($recordId, 'Queue');

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

            $changes = $data['changes'] ?: [];

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

    public function entityAfterSave(App\EventHandler $eventHandler)

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

    {

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

     * @param \App\EventHandler $eventHandler

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

                if ($relatedRecordModel->getPreviousValue()) {

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

     */

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

        $recordModel = $eventHandler->getRecordModel();

Line exceeds 120 characters; contains 129 characters
Open

            (new \App\BatchMethod(['method' => 'Queue_Queue_Handler::updateData', 'params' => [$recordModel->getId()]]))->save();

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

    /**

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

            (new \App\BatchMethod(['method' => 'Queue_Queue_Handler::updateData', 'params' => [$recordModel->getId()]]))->save();

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

     *

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

                    $fieldModel = $relatedRecordModel->getField($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

    {

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

                    if ($fieldModel && $fieldModel->isWritable()) {

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

        if ($data) {

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

            $relatedModule = $data['module'];

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

     * Update data from record ID.

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 updateData(int $recordId)

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

    }

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

     * @param int $recordId

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

            if (\App\Record::isExists($relatedRecordId, $relatedModule)) {

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

        $data = \App\Json::decode($recordModel->get('changes')) ?: [];

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

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

    /**

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

            $relatedRecordId = $data['record'];

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

                        $relatedRecordModel->set($fieldName, $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

                    $relatedRecordModel->save();

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

        }

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

     * EntityAfterSave handler function.

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

                }

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

                $relatedRecordModel = \Vtiger_Record_Model::getInstanceById($relatedRecordId, $relatedModule);

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

            }

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

        $recordModel->set('queue_status', 'PLL_COMPLETED')->save();

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

class Queue_Queue_Handler

There are no issues that match your filters.

Category
Status