YetiForceCompany/YetiForceCRM

View on GitHub
modules/Products/models/SummaryWidget.php

Summary

Maintainability
B
4 hrs
Test Coverage
F
0%

Method getProductsServices has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getProductsServices(App\Request $request, Vtiger_Viewer $viewer)
    {
        $fromModule = $request->getByType('fromModule', 'Text');
        $record = $request->getInteger('record');
        $mod = current($request->getArray('mod', 'Alnum'));
Severity: Minor
Found in modules/Products/models/SummaryWidget.php - About 1 hr to fix

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

        public function getProductsServices(App\Request $request, Vtiger_Viewer $viewer)
        {
            $fromModule = $request->getByType('fromModule', 'Text');
            $record = $request->getInteger('record');
            $mod = current($request->getArray('mod', 'Alnum'));
    Severity: Minor
    Found in modules/Products/models/SummaryWidget.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

    Function getModulesAndCount has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function getModulesAndCount(Vtiger_Record_Model $parentRecordModel)
        {
            $modules = [];
            foreach (self::MODULES as $moduleName) {
                $count = 0;
    Severity: Minor
    Found in modules/Products/models/SummaryWidget.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

    The method getProductsServices() has an NPath complexity of 240. The configured NPath complexity threshold is 200.
    Open

        public function getProductsServices(App\Request $request, Vtiger_Viewer $viewer)
        {
            $fromModule = $request->getByType('fromModule', 'Text');
            $record = $request->getInteger('record');
            $mod = current($request->getArray('mod', 'Alnum'));

    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 getProductsServices() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
    Open

        public function getProductsServices(App\Request $request, Vtiger_Viewer $viewer)
        {
            $fromModule = $request->getByType('fromModule', 'Text');
            $record = $request->getInteger('record');
            $mod = current($request->getArray('mod', 'Alnum'));

    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 '34', column '22').
    Open

            $pagingModel = new Vtiger_Paging_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 '28', column '14').
    Open

                throw new \App\Exceptions\AppException('Not supported Module');

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

                throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);

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

            $parentRecordModel = Vtiger_Record_Model::getInstanceById($record, $fromModule);

    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\Privilege' in method 'getProductsServices'.
    Open

            if (!\App\Privilege::isPermitted($fromModule, 'DetailView', $record) || !\App\Privilege::isPermitted($mod)) {

    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\Privilege' in method 'getProductsServices'.
    Open

            if (!\App\Privilege::isPermitted($fromModule, 'DetailView', $record) || !\App\Privilege::isPermitted($mod)) {

    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_RelationListView_Model' in method 'getModulesAndCount'.
    Open

                $relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $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 'CRMEntity' in method 'getProductsServices'.
    Open

                $moduleInstance = CRMEntity::getInstance($mod);

    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_RelationListView_Model' in method 'getProductsServices'.
    Open

            $relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $mod);

    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\Privilege' in method 'getModulesAndCount'.
    Open

                if (!\App\Privilege::isPermitted($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

    Define a constant instead of duplicating this literal "limit" 3 times.
    Open

            if (!empty($request->getInteger('limit'))) {

    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 \CRMEntity->default_sort_order
    Open

                if ($moduleInstance->default_order_by && $moduleInstance->default_sort_order) {

    Reference to undeclared property \CRMEntity->default_order_by
    Open

                    foreach ((array) $moduleInstance->default_order_by as $value) {

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('RELATED_RECORDS', $recordsModels);
    Severity: Critical
    Found in modules/Products/models/SummaryWidget.php by phan

    Return type of getModulesAndCount() is undeclared type \type
    Open

        public static function getModulesAndCount(Vtiger_Record_Model $parentRecordModel)

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('RECORD_PAGING_MODEL', $pagingModel);
    Severity: Critical
    Found in modules/Products/models/SummaryWidget.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

                $viewer->assign('RELATED_RECORDS_TREE', $relationListView->getTreeEntries());
    Severity: Critical
    Found in modules/Products/models/SummaryWidget.php by phan

    Returning type array<string>|array{}</string> but getModulesAndCount() is declared to return \type
    Open

            return $modules;

    Reference to undeclared property \CRMEntity->default_order_by
    Open

                if ($moduleInstance->default_order_by && $moduleInstance->default_sort_order) {

    Call to undeclared method \Vtiger_Viewer::assign
    Open

                $viewer->assign('RELATED_HEADERS_TREE', $relationListView->getTreeHeaders());
    Severity: Critical
    Found in modules/Products/models/SummaryWidget.php by phan

    Reference to undeclared property \CRMEntity->default_sort_order
    Open

                        $orderBy[$value] = $moduleInstance->default_sort_order;

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('RELATED_HEADERS', $recordsHeader);
    Severity: Critical
    Found in modules/Products/models/SummaryWidget.php by phan

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

    class Products_SummaryWidget_Model

    The class Products_SummaryWidget_Model is not named in CamelCase.
    Open

    class Products_SummaryWidget_Model
    {
        const MODULES = ['Products', 'OutsourcedProducts', 'Assets', 'Services', 'OSSOutsourcedServices', 'OSSSoldServices'];
        const CATEGORY_MODULES = ['Products', 'OutsourcedProducts', 'Services', 'OSSOutsourcedServices'];
    
    

    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

            foreach (self::MODULES as $moduleName) {

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

                    $count += (int) $relationListView->getRelatedTreeEntriesCount();

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

                throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);

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

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

                if (!$relationListView || !$relationListView->getRelationModel()) {

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

            $mod = current($request->getArray('mod', 'Alnum'));

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

            $limit = 10;

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

                $limit = $request->getInteger('limit');

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

                if ($moduleInstance->default_order_by && $moduleInstance->default_sort_order) {

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

                    foreach ((array) $moduleInstance->default_order_by as $value) {

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

            $recordsModels = $relationListView->getEntries($pagingModel);

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

            $recordsHeader = $relationListView->getHeaders();

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

         */

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

                $count = 0;

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

                if (\in_array($moduleName, self::CATEGORY_MODULES)) {

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

                $count += (int) $relationListView->getRelatedEntriesCount();

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

            $fromModule = $request->getByType('fromModule', 'Text');

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

            $record = $request->getInteger('record');

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

            }

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

            $orderBy = $request->getArray('orderby', \App\Purifier::STANDARD, [], \App\Purifier::SQL);

    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 (!\App\Privilege::isPermitted($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

            $viewer->assign('RECORD_PAGING_MODEL', $pagingModel);

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

                    continue;

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

                $modules[$moduleName] = $count;

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

            if (!\in_array($mod, self::MODULES)) {

    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 related modules record counts.

    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 new self();

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

                $moduleInstance = CRMEntity::getInstance($mod);

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

            $viewer->assign('RELATED_HEADERS', $recordsHeader);

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

         *

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

                    continue;

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

            if (!\App\Privilege::isPermitted($fromModule, 'DetailView', $record) || !\App\Privilege::isPermitted($mod)) {

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

            $pagingModel = new Vtiger_Paging_Model();

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

            if (empty($orderBy)) {

    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 (\in_array($mod, self::CATEGORY_MODULES)) {

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

            $modules = [];

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

                }

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

            $parentRecordModel = Vtiger_Record_Model::getInstanceById($record, $fromModule);

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

                $relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $moduleName);

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

                throw new \App\Exceptions\AppException('Not supported Module');

    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 getModulesAndCount(Vtiger_Record_Model $parentRecordModel)

    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('RELATED_RECORDS', $recordsModels);

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

        const MODULES = ['Products', 'OutsourcedProducts', 'Assets', 'Services', 'OSSOutsourcedServices', 'OSSSoldServices'];

    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

            if (!empty($request->getInteger('limit'))) {

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

            $pagingModel->set('limit', $limit);

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

                    $orderBy = [];

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

            if (!empty($orderBy)) {

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

                $relationListView->set('orderby', $orderBy);

    Line exceeds 120 characters; contains 121 characters
    Open

        const MODULES = ['Products', 'OutsourcedProducts', 'Assets', 'Services', 'OSSOutsourcedServices', 'OSSSoldServices'];

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

            array_splice($recordsHeader, 3);

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

        const CATEGORY_MODULES = ['Products', 'OutsourcedProducts', 'Services', 'OSSOutsourcedServices'];

    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

        {

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

            return $modules;

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

            $pagingModel->set('page', 1);

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

                        $orderBy[$value] = $moduleInstance->default_sort_order;

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

                $viewer->assign('RELATED_RECORDS_TREE', $relationListView->getTreeEntries());

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

         * @return type

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

        public function getProductsServices(App\Request $request, Vtiger_Viewer $viewer)

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

            $relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $mod);

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

                $viewer->assign('RELATED_HEADERS_TREE', $relationListView->getTreeHeaders());

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

            }

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

    class Products_SummaryWidget_Model

    There are no issues that match your filters.

    Category
    Status