Method getTreeList
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getTreeList()
{
$trees = [];
$lastId = 0;
$dataReader = (new App\Db\Query())
Missing class import via use statement (line '59', column '22'). Open
$dataReader = (new App\Db\Query())
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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'));
- Read upRead up
- Exclude checks
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()),
- Read upRead up
- Exclude checks
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',
- Read upRead up
- Exclude checks
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,
- Read upRead up
- Exclude checks
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;
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$dataReader = (new App\Db\Query())
- Exclude checks
Call to method setFields
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$listViewModel->getQueryGenerator()->setFields(['id', $this->getTreeField()['fieldname']]);
- Exclude checks
Reference to undeclared property \Vtiger_TreeInventoryModal_Model->lastTreeId
Open
'id' => $this->lastTreeId,
- Exclude checks
Reference to undeclared property \Vtiger_TreeInventoryModal_Model->lastTreeId
Open
++$this->lastTreeId;
- Exclude checks
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
- Exclude checks
The class Vtiger_TreeInventoryModal_Model is not named in CamelCase. Open
class Vtiger_TreeInventoryModal_Model extends Vtiger_TreeCategoryModal_Model
{
/**
* @var bool Auto register events
*/
- Read upRead up
- Exclude checks
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
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'record_id' => $item->getId(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'category' => ['checked' => false]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $tree;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
++$this->lastTreeId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'text' => \App\Language::translate($row['name'], $this->getModuleName()),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TreeInventoryModal', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($listViewModel->getAllEntries() as $item) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parent = (int) ltrim($item->get($this->getTreeField()['fieldname']), 'T');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
end($pieces);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parent = (int) ltrim(prev($pieces), 'T');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->lastTreeId = $lastId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tree[] = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => 'category',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function getTreeList()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tree = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($treeID > $lastId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Retrieves all records and categories.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$treeID = (int) ltrim($row['tree'], 'T');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $trees;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$trees = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'record_id' => $row['tree'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance->set('module', $moduleModel)->set('moduleName', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'text' => $item->getName(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$treeList = $this->getTreeList();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'attr' => 'record',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pieces = explode('::', $row['parentTree']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var bool Auto register events
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $autoRegisterEvents = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Creates a tree for records.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$listViewModel->getQueryGenerator()->setFields(['id', $this->getTreeField()['fieldname']]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'parent' => 0 === $parent ? '#' : $parent,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$lastId = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $instance;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$treeData = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tree = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'id' => $treeID,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$lastId = $treeID;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getInstance(Vtiger_Module_Model $moduleModel)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getTreeData()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function getRecords()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'id' => $this->lastTreeId,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_trees_templates_data')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$trees[$treeID] = $tree;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while (isset($treeList[$tree['parent']]) && !\in_array($treeList[$tree['parent']], $treeData)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'state' => ['disabled' => true]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($row['icon'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$treeData[] = $tree;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tree = $treeList[$tree['parent']];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'parent' => 0 === $parent ? '#' : $parent,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'icon' => "js-detail__icon yfm-{$this->getModuleName()}",
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Creates a tree for category.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new App\Db\Query())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tree['icon'] = $row['icon'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleName = $moduleModel->get('name');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance = new $modelClassName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$listViewModel = Vtiger_ListView_Model::getInstanceForPopup($this->getModuleName(), $this->get('srcModule'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['templateid' => $this->getTemplate()])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => 'category',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return array_merge($treeData, $records);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$records = $this->getRecords();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($records as $tree) {
- Exclude checks
Class name "Vtiger_TreeInventoryModal_Model" is not in camel caps format Open
class Vtiger_TreeInventoryModal_Model extends Vtiger_TreeCategoryModal_Model
- Exclude checks