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'));
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'));
- 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 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;
- 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
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'));
- Read upRead up
- Exclude checks
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'));
- Read upRead up
- Exclude checks
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();
- 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 '28', column '14'). Open
throw new \App\Exceptions\AppException('Not supported Module');
- 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 '25', column '14'). Open
throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);
- 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_Record_Model' in method 'getProductsServices'. Open
$parentRecordModel = Vtiger_Record_Model::getInstanceById($record, $fromModule);
- 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\Privilege' in method 'getProductsServices'. Open
if (!\App\Privilege::isPermitted($fromModule, 'DetailView', $record) || !\App\Privilege::isPermitted($mod)) {
- 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\Privilege' in method 'getProductsServices'. Open
if (!\App\Privilege::isPermitted($fromModule, 'DetailView', $record) || !\App\Privilege::isPermitted($mod)) {
- 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_RelationListView_Model' in method 'getModulesAndCount'. Open
$relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $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 'CRMEntity' in method 'getProductsServices'. Open
$moduleInstance = CRMEntity::getInstance($mod);
- 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_RelationListView_Model' in method 'getProductsServices'. Open
$relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $mod);
- 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\Privilege' in method 'getModulesAndCount'. Open
if (!\App\Privilege::isPermitted($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
Define a constant instead of duplicating this literal "limit" 3 times. Open
if (!empty($request->getInteger('limit'))) {
- 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 \CRMEntity->default_sort_order
Open
if ($moduleInstance->default_order_by && $moduleInstance->default_sort_order) {
- Exclude checks
Reference to undeclared property \CRMEntity->default_order_by
Open
foreach ((array) $moduleInstance->default_order_by as $value) {
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('RELATED_RECORDS', $recordsModels);
- Exclude checks
Return type of getModulesAndCount()
is undeclared type \type
Open
public static function getModulesAndCount(Vtiger_Record_Model $parentRecordModel)
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('RECORD_PAGING_MODEL', $pagingModel);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('RELATED_RECORDS_TREE', $relationListView->getTreeEntries());
- Exclude checks
Returning type array<string>|array{}</string>
but getModulesAndCount()
is declared to return \type
Open
return $modules;
- Exclude checks
Reference to undeclared property \CRMEntity->default_order_by
Open
if ($moduleInstance->default_order_by && $moduleInstance->default_sort_order) {
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('RELATED_HEADERS_TREE', $relationListView->getTreeHeaders());
- Exclude checks
Reference to undeclared property \CRMEntity->default_sort_order
Open
$orderBy[$value] = $moduleInstance->default_sort_order;
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('RELATED_HEADERS', $recordsHeader);
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Products_SummaryWidget_Model
- Exclude checks
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'];
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (self::MODULES as $moduleName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$count += (int) $relationListView->getRelatedTreeEntriesCount();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);
- 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
* @param Vtiger_Record_Model $parentRecordModel
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$relationListView || !$relationListView->getRelationModel()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mod = current($request->getArray('mod', 'Alnum'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$limit = 10;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$limit = $request->getInteger('limit');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($moduleInstance->default_order_by && $moduleInstance->default_sort_order) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ((array) $moduleInstance->default_order_by as $value) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordsModels = $relationListView->getEntries($pagingModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordsHeader = $relationListView->getHeaders();
- 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
$count = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array($moduleName, self::CATEGORY_MODULES)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$count += (int) $relationListView->getRelatedEntriesCount();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fromModule = $request->getByType('fromModule', 'Text');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record = $request->getInteger('record');
- 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
$orderBy = $request->getArray('orderby', \App\Purifier::STANDARD, [], \App\Purifier::SQL);
- 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 (!\App\Privilege::isPermitted($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
$viewer->assign('RECORD_PAGING_MODEL', $pagingModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules[$moduleName] = $count;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\in_array($mod, self::MODULES)) {
- 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 related modules record counts.
- 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 new self();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleInstance = CRMEntity::getInstance($mod);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('RELATED_HEADERS', $recordsHeader);
- 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
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\App\Privilege::isPermitted($fromModule, 'DetailView', $record) || !\App\Privilege::isPermitted($mod)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pagingModel = new Vtiger_Paging_Model();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($orderBy)) {
- 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 (\in_array($mod, self::CATEGORY_MODULES)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules = [];
- 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
$parentRecordModel = Vtiger_Record_Model::getInstanceById($record, $fromModule);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\AppException('Not supported Module');
- 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
public static function getModulesAndCount(Vtiger_Record_Model $parentRecordModel)
- 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
$viewer->assign('RELATED_RECORDS', $recordsModels);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const MODULES = ['Products', 'OutsourcedProducts', 'Assets', 'Services', 'OSSOutsourcedServices', 'OSSSoldServices'];
- 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 (!empty($request->getInteger('limit'))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pagingModel->set('limit', $limit);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$orderBy = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($orderBy)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationListView->set('orderby', $orderBy);
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
const MODULES = ['Products', 'OutsourcedProducts', 'Assets', 'Services', 'OSSOutsourcedServices', 'OSSSoldServices'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
array_splice($recordsHeader, 3);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const CATEGORY_MODULES = ['Products', 'OutsourcedProducts', 'Services', 'OSSOutsourcedServices'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getCleanInstance()
- 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 $modules;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pagingModel->set('page', 1);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$orderBy[$value] = $moduleInstance->default_sort_order;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('RELATED_RECORDS_TREE', $relationListView->getTreeEntries());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return type
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getProductsServices(App\Request $request, Vtiger_Viewer $viewer)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $mod);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('RELATED_HEADERS_TREE', $relationListView->getTreeHeaders());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Products_SummaryWidget_Model" is not in camel caps format Open
class Products_SummaryWidget_Model
- Exclude checks