YetiForceCompany/YetiForceCRM

View on GitHub
modules/Calendar/relations/GetActivities.php

Summary

Maintainability
A
25 mins
Test Coverage
F
0%

Function getQuery has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function getQuery()
    {
        $moduleName = $this->relationModel->getParentModuleModel()->getName();
        $fields = $this->relationModel->getRelationModuleModel()->getReferenceFieldsForModule($moduleName);
        if (!$fields) {
Severity: Minor
Found in modules/Calendar/relations/GetActivities.php - About 25 mins 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 '24', column '14').
Open

            throw new \App\Exceptions\AppException('ERR_ILLEGAL_VALUE');

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

            \App\Log::error('No relation field | Relation name:' . $this->relationModel->get('name') . ' | Relation id:' . $this->relationModel->getId(), __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 'Calendar_Module_Model' in method 'getQuery'.
Open

                $queryGenerator->addCondition('activitystatus', implode('##', Calendar_Module_Model::getComponentActivityStateLabel('history')), 'e');

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\Request' in method 'getQuery'.
Open

        switch (\App\Request::_get('time')) {

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 'Calendar_Module_Model' in method 'getQuery'.
Open

                $queryGenerator->addCondition('activitystatus', implode('##', Calendar_Module_Model::getComponentActivityStateLabel('current')), 'e');

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

Call to method addCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

                $queryGenerator->addCondition('activitystatus', implode('##', Calendar_Module_Model::getComponentActivityStateLabel('history')), 'e');

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

            \App\Log::error('No relation field | Relation name:' . $this->relationModel->get('name') . ' | Relation id:' . $this->relationModel->getId(), __METHOD__);

Call to method addCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

                $queryGenerator->addCondition('activitystatus', implode('##', Calendar_Module_Model::getComponentActivityStateLabel('current')), 'e');

Call to method addNativeCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

        $queryGenerator->addNativeCondition($conditions);

Argument 1 (moduleName) is false but \Vtiger_Module_Model::getReferenceFieldsForModule() takes string defined at /code/modules/Vtiger/models/Module.php:557
Open

        $fields = $this->relationModel->getRelationModuleModel()->getReferenceFieldsForModule($moduleName);

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

class Calendar_GetActivities_Relation extends Vtiger_GetDependentsList_Relation

The class Calendar_GetActivities_Relation is not named in CamelCase.
Open

class Calendar_GetActivities_Relation extends Vtiger_GetDependentsList_Relation
{
    /** {@inheritdoc} */
    public function getQuery()
    {

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

        $moduleName = $this->relationModel->getParentModuleModel()->getName();

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

        $conditions = ['or'];

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

                $queryGenerator->addCondition('activitystatus', implode('##', Calendar_Module_Model::getComponentActivityStateLabel('current')), 'e');

Line exceeds 120 characters; contains 150 characters
Open

                $queryGenerator->addCondition('activitystatus', implode('##', Calendar_Module_Model::getComponentActivityStateLabel('history')), 'e');

Line exceeds 120 characters; contains 166 characters
Open

            \App\Log::error('No relation field | Relation name:' . $this->relationModel->get('name') . ' | Relation id:' . $this->relationModel->getId(), __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

        $queryGenerator->addNativeCondition($conditions);

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

        switch (\App\Request::_get('time')) {

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

            case 'current':

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

            case 'history':

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

    }

Line exceeds 120 characters; contains 150 characters
Open

                $queryGenerator->addCondition('activitystatus', implode('##', Calendar_Module_Model::getComponentActivityStateLabel('current')), 'e');

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

            throw new \App\Exceptions\AppException('ERR_ILLEGAL_VALUE');

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

                break;

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

        if (!$fields) {

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

            \App\Log::error('No relation field | Relation name:' . $this->relationModel->get('name') . ' | Relation id:' . $this->relationModel->getId(), __METHOD__);

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

            $conditions[] = ["{$fieldModel->getTableName()}.{$fieldModel->getColumnName()}" => $this->relationModel->get('parentRecord')->getId()];

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

                break;

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

            default:

Line exceeds 120 characters; contains 147 characters
Open

            $conditions[] = ["{$fieldModel->getTableName()}.{$fieldModel->getColumnName()}" => $this->relationModel->get('parentRecord')->getId()];

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

    /** {@inheritdoc} */

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

    public function getQuery()

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

        foreach ($fields as $fieldModel) {

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

                $queryGenerator->addCondition('activitystatus', implode('##', Calendar_Module_Model::getComponentActivityStateLabel('history')), 'e');

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

    {

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

        $fields = $this->relationModel->getRelationModuleModel()->getReferenceFieldsForModule($moduleName);

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

        $queryGenerator = $this->relationModel->getQueryGenerator();

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

        }

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

                break;

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

class Calendar_GetActivities_Relation extends Vtiger_GetDependentsList_Relation

There are no issues that match your filters.

Category
Status