YetiForceCompany/YetiForceCRM

View on GitHub
modules/FInvoice/dashboards/SummationByMonths.php

Summary

Maintainability
C
7 hrs
Test Coverage
F
0%

Method getWidgetData has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getWidgetData($moduleName, $owner)
    {
        $rawData = $data = $years = [];
        $dateStart = ((int) date('Y') - 2) . '-01-01';
        $dateEnd = date('Y-m-d', strtotime('last day of december'));
Severity: Major
Found in modules/FInvoice/dashboards/SummationByMonths.php - About 2 hrs to fix

    Function getWidgetData has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getWidgetData($moduleName, $owner)
        {
            $rawData = $data = $years = [];
            $dateStart = ((int) date('Y') - 2) . '-01-01';
            $dateEnd = date('Y-m-d', strtotime('last day of december'));
    Severity: Minor
    Found in modules/FInvoice/dashboards/SummationByMonths.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

    Method process has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function process(App\Request $request)
        {
            $currentUserId = \App\User::getCurrentUserId();
            $viewer = $this->getViewer($request);
            $moduleName = $request->getModule();
    Severity: Minor
    Found in modules/FInvoice/dashboards/SummationByMonths.php - About 1 hr to fix

      Method getFilterFields has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getFilterFields($moduleName): array
          {
              if (!isset($this->filterFields)) {
                  $this->filterFields = [];
                  $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
      Severity: Minor
      Found in modules/FInvoice/dashboards/SummationByMonths.php - About 1 hr to fix

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

            public function getFilterFields($moduleName): array
            {
                if (!isset($this->filterFields)) {
                    $this->filterFields = [];
                    $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
        Severity: Minor
        Found in modules/FInvoice/dashboards/SummationByMonths.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

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

            public function process(App\Request $request)
            {
                $currentUserId = \App\User::getCurrentUserId();
                $viewer = $this->getViewer($request);
                $moduleName = $request->getModule();
        Severity: Minor
        Found in modules/FInvoice/dashboards/SummationByMonths.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

        The method getWidgetData() has an NPath complexity of 448. The configured NPath complexity threshold is 200.
        Open

            public function getWidgetData($moduleName, $owner)
            {
                $rawData = $data = $years = [];
                $dateStart = ((int) date('Y') - 2) . '-01-01';
                $dateEnd = date('Y-m-d', strtotime('last day of december'));

        NPathComplexity

        Since: 0.1

        The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

        Example

        class Foo {
            function bar() {
                // lots of complicated code
            }
        }

        Source https://phpmd.org/rules/codesize.html#npathcomplexity

        The method getWidgetData() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
        Open

            public function getWidgetData($moduleName, $owner)
            {
                $rawData = $data = $years = [];
                $dateStart = ((int) date('Y') - 2) . '-01-01';
                $dateEnd = date('Y-m-d', strtotime('last day of december'));

        CyclomaticComplexity

        Since: 0.1

        Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

        Example

        // Cyclomatic Complexity = 11
        class Foo {
        1   public function example() {
        2       if ($a == $b) {
        3           if ($a1 == $b1) {
                        fiddle();
        4           } elseif ($a2 == $b2) {
                        fiddle();
                    } else {
                        fiddle();
                    }
        5       } elseif ($c == $d) {
        6           while ($c == $d) {
                        fiddle();
                    }
        7        } elseif ($e == $f) {
        8           for ($n = 0; $n < $h; $n++) {
                        fiddle();
                    }
                } else {
                    switch ($z) {
        9               case 1:
                            fiddle();
                            break;
        10              case 2:
                            fiddle();
                            break;
        11              case 3:
                            fiddle();
                            break;
                        default:
                            fiddle();
                            break;
                    }
                }
            }
        }

        Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

        Missing class import via use statement (line '110', column '12').
        Open

                $y = new \yii\db\Expression('extract(year FROM saledate)');

        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 '111', column '12').
        Open

                $m = new \yii\db\Expression('extract(month FROM saledate)');

        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 '112', column '12').
        Open

                $s = new \yii\db\Expression("SUM({$sumColumnName})");

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

                    $field = new \Vtiger_Field_Model();

        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 '119', column '40').
        Open

                $queryGenerator->setCustomGroup([new \yii\db\Expression('y'), new \yii\db\Expression('m')]);

        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 '108', column '25').
        Open

                $queryGenerator = new \App\QueryGenerator($moduleName);

        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 '119', column '69').
        Open

                $queryGenerator->setCustomGroup([new \yii\db\Expression('y'), new \yii\db\Expression('m')]);

        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_Module_Model' in method 'getFilterFields'.
        Open

                    $moduleModel = Vtiger_Module_Model::getInstance($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

        The method process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $viewer->view('dashboards/SummationByMonths.tpl', $moduleName);
                }

        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\Language' in method 'getFilterFields'.
        Open

                        $picklistValues[$fieldModelGross->getColumnName()] = \App\Language::translate($fieldModelGross->getFieldLabel(), $fieldModelGross->getModuleName());

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

                } else {
                    $owner = $request->getByType('owner', \App\Purifier::TEXT);
                }

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

            public function process(App\Request $request)
            {
                $currentUserId = \App\User::getCurrentUserId();
                $viewer = $this->getViewer($request);
                $moduleName = $request->getModule();

        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\User' in method 'process'.
        Open

                $currentUserId = \App\User::getCurrentUserId();

        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\Language' in method 'getWidgetData'.
        Open

                    $chartData['labels'][] = App\Language::translate($shortMonth[$i]);

        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\Language' in method 'getFilterFields'.
        Open

                        $picklistValues[$fieldModel->getColumnName()] = \App\Language::translate($fieldModel->getFieldLabel(), $fieldModel->getModuleName());

        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 'Settings_WidgetsManagement_Module_Model' in method 'process'.
        Open

                    $owner = Settings_WidgetsManagement_Module_Model::getDefaultUserId($widget);

        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\Colors' in method 'getWidgetData'.
        Open

                            $yearsData[$y]['backgroundColor'][] = \App\Colors::getRandomColor($y * 10);

        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_Widget_Model' in method 'process'.
        Open

                $widget = Vtiger_Widget_Model::getInstance($request->getInteger('linkid'), $currentUserId);

        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\Language' in method 'getWidgetData'.
        Open

                            'label' => \App\Language::translate('LBL_YEAR', $moduleName) . ' ' . $y,

        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 "fieldvalue" 4 times.
        Open

                        $fieldModel->set('fieldvalue', $value);

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

                    $field->set('name', 'sum_field')

        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.

        Reference to undeclared property \FInvoice_SummationByMonths_Dashboard->filterFields
        Open

                return $this->filterFields;

        Call to method __construct from undeclared class \yii\db\Expression
        Open

                $y = new \yii\db\Expression('extract(year FROM saledate)');

        Call to method getInstance from undeclared class \App\Fields\Owner
        Open

                $accessibleGroups = \App\Fields\Owner::getInstance($moduleName, $currentUserId)->getAccessibleGroupForModule();

        Call to method __construct from undeclared class \yii\db\Expression
        Open

                $queryGenerator->setCustomGroup([new \yii\db\Expression('y'), new \yii\db\Expression('m')]);

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

                $queryGenerator->setCustomGroup([new \yii\db\Expression('y'), new \yii\db\Expression('m')]);

        Call to method getInstance from undeclared class \Vtiger_Widget_Model
        Open

                $widget = Vtiger_Widget_Model::getInstance($request->getInteger('linkid'), $currentUserId);

        Call to method __construct from undeclared class \yii\db\Expression
        Open

                $m = new \yii\db\Expression('extract(month FROM saledate)');

        Call to undeclared method \Vtiger_Viewer::assign
        Open

                $viewer->assign('ACCESSIBLE_GROUPS', $accessibleGroups);

        Reference to undeclared property \FInvoice_SummationByMonths_Dashboard->filterFields
        Open

                if (!isset($this->filterFields)) {

        Reference to undeclared property \FInvoice_SummationByMonths_Dashboard->filterFields
        Open

                    $this->filterFields = [];

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

                $queryGenerator->setCustomColumn($fieldList);

        Call to undeclared method \Vtiger_Viewer::assign
        Open

                $viewer->assign('WIDGET', $widget);

        Reference to undeclared property \FInvoice_SummationByMonths_Dashboard->filterFields
        Open

                        $this->filterFields[$field->getName()] = $field;

        Call to method getCurrentUserId from undeclared class \App\User (Did you mean class \Tests\App\User)
        Open

                $currentUserId = \App\User::getCurrentUserId();

        Call to undeclared method \Vtiger_Viewer::assign
        Open

                $viewer->assign('FILTER_FIELDS', $fields);

        Call to deprecated function \Vtiger_Field_Model::getFieldLabel() defined at /code/modules/Vtiger/models/Field.php:215
        Open

                        $picklistValues[$fieldModel->getColumnName()] = \App\Language::translate($fieldModel->getFieldLabel(), $fieldModel->getModuleName());

        Call to undeclared method \Vtiger_Viewer::assign
        Open

                $viewer->assign('DATA', $data);

        Call to method getInstance from undeclared class \App\Fields\Owner
        Open

                $accessibleUsers = \App\Fields\Owner::getInstance($moduleName, $currentUserId)->getAccessibleUsersForModule();

        Call to deprecated function \Vtiger_Field_Model::getFieldLabel() defined at /code/modules/Vtiger/models/Field.php:215
        Open

                        $picklistValues[$fieldModelGross->getColumnName()] = \App\Language::translate($fieldModelGross->getFieldLabel(), $fieldModelGross->getModuleName());

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

                $queryGenerator->addCondition('saledate', $date, 'bw');

        Call to undeclared method \Vtiger_Viewer::assign
        Open

                $viewer->assign('OWNER', $owner);

        Call to undeclared method \Vtiger_Viewer::assign
        Open

                $viewer->assign('MODULE_NAME', $moduleName);

        Call to undeclared method \Vtiger_Viewer::assign
        Open

                $viewer->assign('ACCESSIBLE_USERS', $accessibleUsers);

        Call to undeclared method \Vtiger_Viewer::assign
        Open

                $viewer->assign('USER_CONDITIONS', $this->conditions);

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

                    $queryGenerator->addCondition('assigned_user_id', $owner, 'e');

        Assigning array{condition:array{0:'between',1:'saledate',2:string,3:string}} to property but \FInvoice_SummationByMonths_Dashboard->conditions is false
        Open

                $this->conditions = ['condition' => ['between', 'saledate', $dateStart, $dateEnd]];

        Call to method __construct from undeclared class \yii\db\Expression
        Open

                $s = new \yii\db\Expression("SUM({$sumColumnName})");

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

                $queryGenerator = new \App\QueryGenerator($moduleName);

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

                $query = $queryGenerator->createQuery();

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

        class FInvoice_SummationByMonths_Dashboard extends Vtiger_IndexAjax_View

        The class FInvoice_SummationByMonths_Dashboard is not named in CamelCase.
        Open

        class FInvoice_SummationByMonths_Dashboard extends Vtiger_IndexAjax_View
        {
            private $conditions = false;
        
            /**

        CamelCaseClassName

        Since: 0.2

        It is considered best practice to use the CamelCase notation to name classes.

        Example

        class class_name {
        }

        Source

        Avoid variables with short names like $m. Configured minimum length is 3.
        Open

                $m = new \yii\db\Expression('extract(month FROM saledate)');

        ShortVariable

        Since: 0.2

        Detects when a field, local, or parameter has a very short name.

        Example

        class Something {
            private $q = 15; // VIOLATION - Field
            public static function main( array $as ) { // VIOLATION - Formal
                $r = 20 + $this->q; // VIOLATION - Local
                for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                    $r += $this->q;
                }
            }
        }

        Source https://phpmd.org/rules/naming.html#shortvariable

        Avoid variables with short names like $y. Configured minimum length is 3.
        Open

                $y = new \yii\db\Expression('extract(year FROM saledate)');

        ShortVariable

        Since: 0.2

        Detects when a field, local, or parameter has a very short name.

        Example

        class Something {
            private $q = 15; // VIOLATION - Field
            public static function main( array $as ) { // VIOLATION - Formal
                $r = 20 + $this->q; // VIOLATION - Local
                for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                    $r += $this->q;
                }
            }
        }

        Source https://phpmd.org/rules/naming.html#shortvariable

        Avoid variables with short names like $s. Configured minimum length is 3.
        Open

                $s = new \yii\db\Expression("SUM({$sumColumnName})");

        ShortVariable

        Since: 0.2

        Detects when a field, local, or parameter has a very short name.

        Example

        class Something {
            private $q = 15; // VIOLATION - Field
            public static function main( array $as ) { // VIOLATION - Formal
                $r = 20 + $this->q; // VIOLATION - Local
                for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                    $r += $this->q;
                }
            }
        }

        Source https://phpmd.org/rules/naming.html#shortvariable

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

             * Process.

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

                $fields = $this->getFilterFields($moduleName);

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

                $accessibleGroups = \App\Fields\Owner::getInstance($moduleName, $currentUserId)->getAccessibleGroupForModule();

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

                $viewer->assign('ACCESSIBLE_GROUPS', $accessibleGroups);

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

             * @return \Vtiger_Field_Model[]

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

            /**

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

                $dateEnd = date('Y-m-d', strtotime('last day of december'));

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

            public function process(App\Request $request)

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

                if (!$request->has('owner')) {

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

                $viewer->assign('DATA', $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

                    $this->filterFields = [];

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

                    $fieldModelGross = $moduleModel->getFieldByName('sum_gross');

        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 ('all' !== $owner) {

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

             * @param string $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

                    $moduleModel = Vtiger_Module_Model::getInstance($moduleName);

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

                        $picklistValues[$fieldModel->getColumnName()] = \App\Language::translate($fieldModel->getFieldLabel(), $fieldModel->getModuleName());

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

             * @return array

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

                    $owner = Settings_WidgetsManagement_Module_Model::getDefaultUserId($widget);

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

                    $owner = $request->getByType('owner', \App\Purifier::TEXT);

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

                        $fieldModel->set('fieldvalue', $value);

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

                    $viewer->view('dashboards/SummationByMonthsContents.tpl', $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

                    $field = new \Vtiger_Field_Model();

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

                        ->set('column', 'sum_field')

        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 getWidgetData($moduleName, $owner)

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

            {

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

                $currentUserId = \App\User::getCurrentUserId();

        Line exceeds 120 characters; contains 172 characters
        Open

                    if ($request->has($fieldModel->getName()) && '' !== ($value = $request->getForSql($fieldModel->getName())) && isset($fieldModel->getPicklistValues()[$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

                $rawData = $data = $years = [];

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

                $queryGenerator->addCondition('saledate', $date, 'bw');

        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

                $viewer->assign('USER_CONDITIONS', $this->conditions);

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

                return $this->filterFields;

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

                }

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

                $this->conditions = ['condition' => ['between', 'saledate', $dateStart, $dateEnd]];

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

                            $tempData[$y][$m] = 0;

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

                    if ($request->has($fieldModel->getName()) && '' !== ($value = $request->getForSql($fieldModel->getName())) && isset($fieldModel->getPicklistValues()[$value])) {

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

                if ($request->has('content')) {

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

                    $viewer->view('dashboards/SummationByMonths.tpl', $moduleName);

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

             * Gets filter fields.

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

                    $fieldModel = $moduleModel->getFieldByName('sum_total');

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

                    $field->set('name', 'sum_field')

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

                        ->set('label', 'DW_SUM_FIELD')

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

                $moduleName = $request->getModule();

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

                $viewer->assign('WIDGET', $widget);

        Line exceeds 120 characters; contains 164 characters
        Open

                        $picklistValues[$fieldModelGross->getColumnName()] = \App\Language::translate($fieldModelGross->getFieldLabel(), $fieldModelGross->getModuleName());

        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

                $queryGenerator = new \App\QueryGenerator($moduleName);

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

             * @param int|string $owner

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

                    'LBL_Jul', 'LBL_Aug', 'LBL_Sep', 'LBL_Oct', 'LBL_Nov', 'LBL_Dec', ];

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

                $y = new \yii\db\Expression('extract(year FROM saledate)');

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

                    $years[] = $y;

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

                    }

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

                            'backgroundColor' => [],

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

                        $yearsData[$y]['stack'] = (string) $y;

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

                return $chartData;

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

            private $conditions = false;

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

                $viewer = $this->getViewer($request);

        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 (!isset($this->filterFields)) {

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

                        $field->set('fieldvalue', $fieldModel->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

                $sumColumnName = $this->getFilterFields($moduleName)['sum_field']->get('fieldvalue') ?: 'sum_gross';

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

                $viewer->assign('MODULE_NAME', $moduleName);

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

                $fieldList = ['y' => $y, 'm' => $m, 's' => $s];

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

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

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

                        for ($m = 0; $m < 12; ++$m) {

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

             *

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

                    'show_chart' => 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

             */

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

            public function getFilterFields($moduleName): array

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

                        ->set('icon', 'mdi mdi-sigma')

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

                    }

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

                $date = "{$dateStart},{$dateEnd}";

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

                $s = new \yii\db\Expression("SUM({$sumColumnName})");

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

                    $queryGenerator->addCondition('assigned_user_id', $owner, 'e');

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

                    'datasets' => [],

        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\Request $request

        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 ($fieldModelGross && $fieldModelGross->isActiveField()) {

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

                        $this->filterFields[$field->getName()] = $field;

        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

                    if (!isset($yearsData[$y])) {

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

                        $tempData[$y][$m - 1] = $value[0];

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

                foreach ($tempData as $year => $yearData) {

        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

                        ->set('fromOutsideList', true)

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

                        ->set('uitype', 16)

        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

                        $picklistValues[$fieldModelGross->getColumnName()] = \App\Language::translate($fieldModelGross->getFieldLabel(), $fieldModelGross->getModuleName());

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

                            'label' => \App\Language::translate('LBL_YEAR', $moduleName) . ' ' . $y,

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

                    }

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

             * Get widget data.

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

                $m = new \yii\db\Expression('extract(month FROM saledate)');

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

                $yearsData = $tempData = [];

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

                $chartData['show_chart'] = (bool) \count($rawData);

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

                $shortMonth = ['LBL_Jan', 'LBL_Feb', 'LBL_Mar', 'LBL_Apr', 'LBL_May', 'LBL_Jun',

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

                }

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

                    $chartData['datasets'][] = $data;

        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

                    $rawData[$row['y']][$row['m']] = [round((float) $row['s'], 2)];

        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

                for ($i = 0; $i < 12; ++$i) {

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

                        ];

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

                $years = array_values(array_unique($years));

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

                        $yearsData[$y] = [

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

                    $yearsData[$year]['data'] = $yearData;

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

                $widget = Vtiger_Widget_Model::getInstance($request->getInteger('linkid'), $currentUserId);

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

                $data = $fields ? $this->getWidgetData($moduleName, $owner) : [];

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

             * @param string     $moduleName

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

                $queryGenerator->setCustomColumn($fieldList);

        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

                $chartData = [

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

                            '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

                foreach ($yearsData as $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

                foreach ($rawData as $y => $raw) {

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

                    foreach ($raw as $m => $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

                $viewer->assign('OWNER', $owner);

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

                $viewer->assign('ACCESSIBLE_USERS', $accessibleUsers);

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

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

                        $field->set('picklistValues', $picklistValues);

        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->setCustomGroup([new \yii\db\Expression('y'), new \yii\db\Expression('m')]);

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

                $chartData['years'] = $years;

        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

                $accessibleUsers = \App\Fields\Owner::getInstance($moduleName, $currentUserId)->getAccessibleUsersForModule();

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

                $viewer->assign('FILTER_FIELDS', $fields);

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

                        ->setModule($moduleModel);

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

                    $picklistValues = [];

        Line exceeds 120 characters; contains 149 characters
        Open

                        $picklistValues[$fieldModel->getColumnName()] = \App\Language::translate($fieldModel->getFieldLabel(), $fieldModel->getModuleName());

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

                        $field->set('fieldvalue', $fieldModelGross->getColumnName());

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

                $dateStart = ((int) date('Y') - 2) . '-01-01';

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

                    'labels' => [],

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

                    $chartData['labels'][] = App\Language::translate($shortMonth[$i]);

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

                            $yearsData[$y]['backgroundColor'][] = \App\Colors::getRandomColor($y * 10);

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

            }

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

        class FInvoice_SummationByMonths_Dashboard extends Vtiger_IndexAjax_View

        There are no issues that match your filters.

        Category
        Status