YetiForceCompany/YetiForceCRM

View on GitHub
modules/com_vtiger_workflow/tasks/SumFieldFromDependent.php

Summary

Maintainability
A
1 hr
Test Coverage
B
88%

Method doTask has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function doTask($recordModel)
    {
        [$referenceField, $moduleName, $fieldName] = explode('::', $this->targetField);
        $relationFieldModel = $recordModel->getModule()->getFieldByName($referenceField);
        $ids = [];
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/SumFieldFromDependent.php - About 1 hr to fix

    Function doTask has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public function doTask($recordModel)
        {
            [$referenceField, $moduleName, $fieldName] = explode('::', $this->targetField);
            $relationFieldModel = $recordModel->getModule()->getFieldByName($referenceField);
            $ids = [];
    Severity: Minor
    Found in modules/com_vtiger_workflow/tasks/SumFieldFromDependent.php - About 45 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 '39', column '27').
    Open

                    $queryGenerator = new \App\QueryGenerator($recordModel->getModuleName());

    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 assigning values to variables in if clauses and the like (line '34', column '7').
    Open

        public function doTask($recordModel)
        {
            [$referenceField, $moduleName, $fieldName] = explode('::', $this->targetField);
            $relationFieldModel = $recordModel->getModule()->getFieldByName($referenceField);
            $ids = [];

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Avoid using static access to class '\App\Record' in method 'doTask'.
    Open

                if (\App\Record::isExists($id, $moduleName)) {

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

                    $relatedModel = \Vtiger_Record_Model::getInstanceById($id, $moduleName);

    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 __construct from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

                    $queryGenerator = new \App\QueryGenerator($recordModel->getModuleName());

    Reference to undeclared property \SumFieldFromDependent->targetField
    Open

            [$referenceField, $moduleName, $fieldName] = explode('::', $this->targetField);

    Reference to undeclared property \SumFieldFromDependent->conditions
    Open

                        $queryGenerator->setConditions($this->conditions);

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

                        $queryGenerator->setConditions($this->conditions);

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

                    $query = $queryGenerator->createQuery();

    Reference to undeclared property \SumFieldFromDependent->sourceField
    Open

                    $sourceFieldModel = $recordModel->getModule()->getFieldByName($this->sourceField);

    Reference to undeclared property \SumFieldFromDependent->sourceField
    Open

                    $queryGenerator->setField($this->sourceField);

    Reference to undeclared property \SumFieldFromDependent->conditions
    Open

                    if (!empty($this->conditions)) {

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

                    $queryGenerator->setField($this->sourceField);

    Reference to instance property permissions from undeclared class \App\QueryGenerator
    Open

                    $queryGenerator->permissions = false;

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

    class SumFieldFromDependent extends VTTask

    A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 12 and the first side effect is on line 10.
    Open

    <?php

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

            return ['targetField', 'sourceField', 'conditions'];

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

                $ids[] = $recordModel->get($referenceField);

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

                        $queryGenerator->setConditions($this->conditions);

    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

        /** {@inheritdoc} */

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

                    $query = $queryGenerator->createQuery();

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

                    $relatedModel = \Vtiger_Record_Model::getInstanceById($id, $moduleName);

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

                    $queryGenerator = new \App\QueryGenerator($recordModel->getModuleName());

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

                    $relatedModel->save();

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

         * @var bool

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

                $ids[] = $oldId;

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

                    $queryGenerator->permissions = false;

    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

        }

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

                if (\App\Record::isExists($id, $moduleName)) {

    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 doTask($recordModel)

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

            }

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

            foreach ($ids as $id) {

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

                    $relatedModel->set($fieldName, $columnSumValue ?? 0);

    Line exceeds 120 characters; contains 124 characters
    Open

                    $columnSumValue = $query->sum($sourceFieldModel->getTableName() . '.' . $sourceFieldModel->getColumnName());

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

         */

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

            $relationFieldModel = $recordModel->getModule()->getFieldByName($referenceField);

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

                    $query->andWhere([$relationFieldModel->getTableName() . '.' . $relationFieldModel->getColumnName() => $id, 'vtiger_crmentity.deleted' => 0]);

    Line exceeds 120 characters; contains 157 characters
    Open

                    $query->andWhere([$relationFieldModel->getTableName() . '.' . $relationFieldModel->getColumnName() => $id, 'vtiger_crmentity.deleted' => 0]);

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

            [$referenceField, $moduleName, $fieldName] = explode('::', $this->targetField);

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

                    $queryGenerator->setField($this->sourceField);

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

                    $sourceFieldModel = $recordModel->getModule()->getFieldByName($this->sourceField);

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

            if ($oldId = $recordModel->getPreviousValue($referenceField)) {

    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

                    }

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

                    $columnSumValue = $query->sum($sourceFieldModel->getTableName() . '.' . $sourceFieldModel->getColumnName());

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

        public function getFieldNames()

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

                    if (!empty($this->conditions)) {

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

            if (!$recordModel->isEmpty($referenceField)) {

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

        public $executeImmediately = true;

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

            $ids = [];

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

            }

    There are no issues that match your filters.

    Category
    Status