Function getCustomViewList
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getCustomViewList()
{
$filters = (new \App\Db\Query())->select(['cvid', 'viewname', 'entitytype', 'vtiger_tab.tabid'])
->from('vtiger_customview')
->leftJoin('vtiger_tab', 'vtiger_tab.name = vtiger_customview.entitytype')->all();
- Read upRead up
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 getMenuUrl
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getMenuUrl($row)
{
switch ($row['type']) {
case 0:
$moduleModel = Vtiger_Module_Model::getInstance($row['module']);
- Read upRead up
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
Missing class import via use statement (line '133', column '24'). Open
$fileFilters = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filterDir, FilesystemIterator::SKIP_DOTS));
- 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
Missing class import via use statement (line '133', column '54'). Open
$fileFilters = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filterDir, FilesystemIterator::SKIP_DOTS));
- 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
Missing class import via use statement (line '113', column '23'). Open
$maxSequence = (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
Missing class import via use statement (line '127', column '19'). Open
$filters = (new \App\Db\Query())->select(['cvid', 'viewname', 'entitytype', 'vtiger_tab.tabid'])
- 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
Missing class import via use statement (line '86', column '15'). Open
return (new \App\Db\Query())->select(['tabid', 'name'])->from('vtiger_tab')
- 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
The method getMenuTypes has a boolean flag argument $key, which is a certain sign of a Single Responsibility Principle violation. Open
public function getMenuTypes($key = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid using static access to class 'Vtiger_Loader' in method 'getCustomViewList'. Open
$handlerClass = Vtiger_Loader::getComponentClassName('Filter', $name, $module->get('name'));
- 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_Module_Model' in method 'getMenuUrl'. Open
$moduleModel = Vtiger_Module_Model::getInstance($row['module']);
- 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_Module_Model' in method 'getCustomViewList'. Open
foreach (Vtiger_Module_Model::getAll() as $module) {
- 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 "parentid" 5 times. Open
'id', 'role', 'parentid', 'type', 'sequence', 'module', 'label', 'newwindow',
- 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 "dataurl" 5 times. Open
'dataurl', 'showicon', 'icon', 'sizeicon', 'hotkey', 'filters', 'edit', 'source', 'countentries',
- 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.
Saw possibly unextractable annotation for a fragment of comment '* @param bool true/false':
after bool,
did not see an element name (will guess based on comment order) Open
* @param bool true/false
- Exclude checks
Assigning array{0:'id',1:'role',2:'parentid',3:'type',4:'sequence',5:'module',6:'label',7:'newwindow',8:'dataurl',9:'showicon',10:'icon',11:'sizeicon',12:'hotkey',13:'filters',14:'edit',15:'source',16:'countentries'}
to property but \Settings_Menu_Module_Model->editFields
is \strung[]
Open
protected $editFields = [
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$filters = (new \App\Db\Query())->select(['cvid', 'viewname', 'entitytype', 'vtiger_tab.tabid'])
- Exclude checks
Saw unextractable annotation for comment '* @return <settings_menu_module_model>'</settings_menu_module_model>
Open
* @return <Settings_Menu_Module_Model>
- Exclude checks
Property \Settings_Menu_Module_Model->editFields
has undeclared type \strung[]
(Did you mean string) Open
protected $editFields = [
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$maxSequence = (new \App\Db\Query())
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
return (new \App\Db\Query())->select(['tabid', 'name'])->from('vtiger_tab')
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_Menu_Module_Model
- Exclude checks
The class Settings_Menu_Module_Model is not named in CamelCase. Open
class Settings_Menu_Module_Model
{
/**
* Fields to edit.
*
- 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
'dataurl', 'showicon', 'icon', 'sizeicon', 'hotkey', 'filters', 'edit', 'source', 'countentries',
- 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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get editable fields.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $url;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Fields to edit.
- 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
$moduleModel = Vtiger_Module_Model::getInstance($row['module']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$url = 'index.php?module=' . $row['name'] . '&view=List&viewname=' . $row['dataurl'] . '&mid=' . $row['id'] . (empty($row['parentid']) ? '' : ('&parent=' . $row['parentid']));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_customview')
- Exclude checks
Line exceeds 120 characters; contains 136 characters Open
$fileFilters = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filterDir, FilesystemIterator::SKIP_DOTS));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'entitytype' => $module->get('name'),
- 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
if (false === $key) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return array_search($val, \App\Menu::TYPES);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getMenuUrl($row)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 4:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return (int) $maxSequence;
- 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
* Function to get all filters.
- 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 $this->editFields;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 0:
- Exclude checks
Line exceeds 120 characters; contains 191 characters Open
$url = 'index.php?module=' . $row['name'] . '&view=List&viewname=' . $row['dataurl'] . '&mid=' . $row['id'] . (empty($row['parentid']) ? '' : ('&parent=' . $row['parentid']));
- 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
public function getModulesList(): 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
$modules = $this->getModulesList();
- 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
$filterDir = 'modules' . DIRECTORY_SEPARATOR . $module->get('name') . DIRECTORY_SEPARATOR . 'filters';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getMenuTypes($key = false)
- 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
switch ($row['type']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$url = addslashes($row['dataurl']);
- 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
->max('id');
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$url = $row['dataurl'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return (new \App\Db\Query())->select(['tabid', 'name'])->from('vtiger_tab')
- 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
foreach (Vtiger_Module_Model::getAll() as $module) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return <Settings_Menu_Module_Model>
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return new self();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getEditFields()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return \App\Menu::TYPES;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$url = $row['dataurl'];
- 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
->where(['not in', 'name', ['Users', 'ModComments']])
- 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 string[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->andWhere(['or', ['isentitytype' => 1], ['name' => ['OSSMail', 'Rss']]])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->andWhere(['presence' => 0])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->all();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($modules as $key => $module) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!Vtiger_Module_Model::getInstance($module['name'])->isQuickCreateSupported()) {
- 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
$filters = (new \App\Db\Query())->select(['cvid', 'viewname', 'entitytype', 'vtiger_tab.tabid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$handlerClass = Vtiger_Loader::getComponentClassName('Filter', $name, $module->get('name'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $editFields = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get instance.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool true/false
- 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
default:
- 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
public static function getLastId()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('yetiforce_menu')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'cvid' => $name,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var strung[]
- 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
case 1:
- 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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($modules[$key]);
- 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
$filters[] = [
- 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
return $filters;
- 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 \App\Menu::TYPES[$key];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getMenuTypeKey($val)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 7:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Module list.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'id', 'role', 'parentid', 'type', 'sequence', 'module', 'label', 'newwindow',
- 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
public static function getInstance()
- 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
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($fileFilters as $filter) {
- 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
* Get a list of modules with quick create support.
- 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
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $modules;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$maxSequence = (new \App\Db\Query())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (file_exists($filterDir)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fileFilters = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filterDir, FilesystemIterator::SKIP_DOTS));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'viewname' => (new $handlerClass())->getViewName(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'tabid' => $module->getId(),
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->orderBy('tabsequence')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->leftJoin('vtiger_tab', 'vtiger_tab.name = vtiger_customview.entitytype')->all();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$name = str_replace('.php', '', $filter->getFilename());
- 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
$url = $moduleModel->getDefaultUrl() . '&mid=' . $row['id'] . (empty($row['parentid']) ? '' : ('&parent=' . $row['parentid']));
- Exclude checks
Line exceeds 120 characters; contains 143 characters Open
$url = $moduleModel->getDefaultUrl() . '&mid=' . $row['id'] . (empty($row['parentid']) ? '' : ('&parent=' . $row['parentid']));
- 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
public function getQuickCreateModuleList(): 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
public function getCustomViewList()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (class_exists($handlerClass)) {
- Exclude checks
Class name "Settings_Menu_Module_Model" is not in camel caps format Open
class Settings_Menu_Module_Model
- Exclude checks