YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
1 hr
Test Coverage
F
28%

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

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

    Missing class import via use statement (line '72', column '14').
    Open

                throw new \App\Exceptions\AppException('ERR_TREE_NOT_FOUND');
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phpmd

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

            $dataReader = (new App\Db\Query())
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phpmd

    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 '67', column '21').
    Open

            $fieldTemp = (new App\Db\Query())->select(['tablename', 'columnname', 'fieldname', 'fieldparams'])
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

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

    Avoid using static access to class '\App\Language' in method 'getTreeList'.
    Open

                    'text' => \App\Language::translate($row['name'], $this->getModuleName()),
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phpmd

    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\Module' in method 'getTreeField'.
    Open

                ->where(['uitype' => 302, 'tabid' => \App\Module::getModuleId($this->getModuleName())])
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phpmd

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

            $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TreeView', $moduleName);
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phpmd

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

            if ($this->has('fieldTemp')) {
    Severity: Critical
    Found in modules/Vtiger/models/TreeView.php by sonar-php

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

                    'state' => ($row['state']) ? $row['state'] : '',
    Severity: Critical
    Found in modules/Vtiger/models/TreeView.php by sonar-php

    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.

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

        public function getTemplate()
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phan

    Reference to undeclared property \Vtiger_TreeView_Model->lastTreeId
    Open

            $this->lastTreeId = $lastId;
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phan

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

            return $tree;
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phan

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

            $fieldTemp = (new App\Db\Query())->select(['tablename', 'columnname', 'fieldname', 'fieldparams'])
    Severity: Critical
    Found in modules/Vtiger/models/TreeView.php by phan

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

            $dataReader = (new App\Db\Query())
    Severity: Critical
    Found in modules/Vtiger/models/TreeView.php by phan

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

    class Vtiger_TreeView_Model extends \App\Base

    The class Vtiger_TreeView_Model is not named in CamelCase.
    Open

    class Vtiger_TreeView_Model extends \App\Base
    {
        public static $_cached_instance;
    
        /**
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phpmd

    CamelCaseClassName

    Since: 0.2

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

    Example

    class class_name {
    }

    Source

    The property $_cached_instance is not named in camelCase.
    Open

    class Vtiger_TreeView_Model extends \App\Base
    {
        public static $_cached_instance;
    
        /**
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phpmd

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    Property name "$_cached_instance" should not be prefixed with an underscore to indicate visibility
    Open

        public static $_cached_instance;

    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

         * Load tree field info.

    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

        public function getTreeViewUrl()

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

         * Function to get the Module Name.

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

         * @return bool

    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

                ->where(['uitype' => 302, 'tabid' => \App\Module::getModuleId($this->getModuleName())])

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

        public static function getInstance(string $moduleName)

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

         * Load tree.

    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

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

    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

        public function getModuleName()

    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

            $fieldTemp = (new App\Db\Query())->select(['tablename', 'columnname', 'fieldname', 'fieldparams'])

    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 Vtiger_TreeView_Model

    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

                }

    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 string

    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 getTreeField()

    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 'index.php?module=' . $this->getModuleName() . '&view=TreeRecords';

    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

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

    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

         *

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

         * @return string Module name

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

         * Load tree tab label.

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

         * Load tree ID.

    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(self::$_cached_instance[$moduleName])) {

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

            $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TreeView', $moduleName);

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

        public function getTreeList()

    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

        }

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

            return 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

        public function getTemplate()

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

         *

    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

            $this->lastTreeId = $lastId;

    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 'LBL_TREE_VIEW';

    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 ($this->has('fieldTemp')) {

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

            $this->set('fieldTemp', $fieldTemp);

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

         * @throws \App\Exceptions\AppException

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

            return self::$_cached_instance[$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

                ->createCommand()->query();

    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

                    $lastId = $treeID;

    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

                return $this->get('fieldTemp');

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

        /**

    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

         * Load records tree address.

    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 string

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

                    'icon' => $row['icon'],

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

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

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

                return self::$_cached_instance[$moduleName];

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

            self::$_cached_instance[$moduleName] = $instance->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

                if ($treeID > $lastId) {

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

            return $this->get('moduleName');

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

            return $this->getTreeField()['fieldparams'];

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

         *

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

                ->one();

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

            return $fieldTemp;

    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 string $moduleName

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

         * Active tree tab.

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

        public function isActive()

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

        public function 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

        /**

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

        {

    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

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

    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

            return $tree;

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

        public static $_cached_instance;

    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

                ->from('vtiger_field')

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

         * Static Function to get the instance of Vtiger TreeView Model for the given Vtiger Module 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

                ->from('vtiger_trees_templates_data')

    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

         *

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

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

         * @return string - url

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

         */

    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

                    'state' => ($row['state']) ? $row['state'] : '',

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

    class Vtiger_TreeView_Model extends \App\Base

    The variable $_cached_instance is not named in camelCase.
    Open

        public static function getInstance(string $moduleName)
        {
            if (isset(self::$_cached_instance[$moduleName])) {
                return self::$_cached_instance[$moduleName];
            }
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $_cached_instance is not named in camelCase.
    Open

        public static function getInstance(string $moduleName)
        {
            if (isset(self::$_cached_instance[$moduleName])) {
                return self::$_cached_instance[$moduleName];
            }
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $_cached_instance is not named in camelCase.
    Open

        public static function getInstance(string $moduleName)
        {
            if (isset(self::$_cached_instance[$moduleName])) {
                return self::$_cached_instance[$moduleName];
            }
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $_cached_instance is not named in camelCase.
    Open

        public static function getInstance(string $moduleName)
        {
            if (isset(self::$_cached_instance[$moduleName])) {
                return self::$_cached_instance[$moduleName];
            }
    Severity: Minor
    Found in modules/Vtiger/models/TreeView.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    There are no issues that match your filters.

    Category
    Status