YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/models/TreeInventoryModal.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

Method getTreeList has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function getTreeList()
    {
        $trees = [];
        $lastId = 0;
        $dataReader = (new App\Db\Query())
Severity: Minor
Found in modules/Vtiger/models/TreeInventoryModal.php - About 1 hr to fix

    Missing class import via use statement (line '59', column '22').
    Open

            $dataReader = (new App\Db\Query())

    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_Loader' in method 'getInstance'.
    Open

            $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TreeInventoryModal', $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_ListView_Model' in method 'getRecords'.
    Open

            $listViewModel = Vtiger_ListView_Model::getInstanceForPopup($this->getModuleName(), $this->get('srcModule'));

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

                    'text' => \App\Language::translate($row['name'], $this->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

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

                    'type' => 'category',

    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 "parent" 5 times.
    Open

                    'parent' => 0 === $parent ? '#' : $parent,

    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 \Vtiger_TreeInventoryModal_Model->lastTreeId
    Open

            $this->lastTreeId = $lastId;

    Call to undeclared method \App\Db\Query::from
    Open

            $dataReader = (new App\Db\Query())

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

            $listViewModel->getQueryGenerator()->setFields(['id', $this->getTreeField()['fieldname']]);

    Reference to undeclared property \Vtiger_TreeInventoryModal_Model->lastTreeId
    Open

                    'id' => $this->lastTreeId,

    Reference to undeclared property \Vtiger_TreeInventoryModal_Model->lastTreeId
    Open

                ++$this->lastTreeId;

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

    class Vtiger_TreeInventoryModal_Model extends Vtiger_TreeCategoryModal_Model

    The class Vtiger_TreeInventoryModal_Model is not named in CamelCase.
    Open

    class Vtiger_TreeInventoryModal_Model extends Vtiger_TreeCategoryModal_Model
    {
        /**
         * @var bool Auto register events
         */

    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

         * @return array

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

        {

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

                    'record_id' => $item->getId(),

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

                    'category' => ['checked' => false]

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

            return $tree;

    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->lastTreeId;

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

            }

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

                    'text' => \App\Language::translate($row['name'], $this->getModuleName()),

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

        {

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

            $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TreeInventoryModal', $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

            foreach ($listViewModel->getAllEntries() as $item) {

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

                $parent = (int) ltrim($item->get($this->getTreeField()['fieldname']), 'T');

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

                end($pieces);

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

                $parent = (int) ltrim(prev($pieces), 'T');

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

            $this->lastTreeId = $lastId;

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

                $tree[] = [

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

                    'type' => 'category',

    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 array

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

        private function getTreeList()

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

                $tree = [

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

                if ($treeID > $lastId) {

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

         * Retrieves all records and categories.

    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

                $treeID = (int) ltrim($row['tree'], 'T');

    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 $trees;

    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

            $trees = [];

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

                    'record_id' => $row['tree'],

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

            $instance->set('module', $moduleModel)->set('moduleName', $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

                    'text' => $item->getName(),

    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

            $treeList = $this->getTreeList();

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

                    'attr' => 'record',

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

                $pieces = explode('::', $row['parentTree']);

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

         * @var bool Auto register events

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

        public $autoRegisterEvents = false;

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

         * Creates a tree for records.

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

            $listViewModel->getQueryGenerator()->setFields(['id', $this->getTreeField()['fieldname']]);

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

                    'parent' => 0 === $parent ? '#' : $parent,

    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

            $lastId = 0;

    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

            return $instance;

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

            $treeData = [];

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

                }

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

            $tree = [];

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

                    'id' => $treeID,

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

                    $lastId = $treeID;

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

        public static function getInstance(Vtiger_Module_Model $moduleModel)

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

        public function getTreeData()

    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

        private function getRecords()

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

                    'id' => $this->lastTreeId,

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

                ->from('vtiger_trees_templates_data')

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

                $trees[$treeID] = $tree;

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

                while (isset($treeList[$tree['parent']]) && !\in_array($treeList[$tree['parent']], $treeData)) {

    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

                    'state' => ['disabled' => true]

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

                if (!empty($row['icon'])) {

    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

                    $treeData[] = $tree;

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

                    $tree = $treeList[$tree['parent']];

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

                    'parent' => 0 === $parent ? '#' : $parent,

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

                    'icon' => "js-detail__icon yfm-{$this->getModuleName()}",

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

                ];

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

         * Creates a tree for category.

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

            $dataReader = (new App\Db\Query())

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

                ->createCommand()->query();

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

                    $tree['icon'] = $row['icon'];

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

            $moduleName = $moduleModel->get('name');

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

            $instance = new $modelClassName();

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

        }

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

            $listViewModel = Vtiger_ListView_Model::getInstanceForPopup($this->getModuleName(), $this->get('srcModule'));

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

                ->where(['templateid' => $this->getTemplate()])

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

                    'type' => 'category',

    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

            return array_merge($treeData, $records);

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

            $records = $this->getRecords();

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

            foreach ($records as $tree) {

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

    class Vtiger_TreeInventoryModal_Model extends Vtiger_TreeCategoryModal_Model

    There are no issues that match your filters.

    Category
    Status