Function getModules
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getModules(): array
{
$modules = [];
$quickCreate = App\Config::module('MailIntegration', 'modulesListQuickCreate', []);
foreach (\App\Relation::getByModule('OSSMailView', true) as $relation) {
- 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
Avoid using static access to class 'App\Config' in method 'process'. Open
$viewer->assign('URL', App\Config::main('site_URL'));
- 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\Mail\Message' in method 'process'. Open
$mail = App\Mail\Message::getScannerByEngine($request->getByType('source'));
- 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\Relation' in method 'getModules'. Open
foreach (\App\Relation::getByModule('OSSMailView', true) as $relation) {
- 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 'getModules'. Open
if (0 === $relation['presence'] && 'getRecordToMails' === $relation['name'] && App\Privilege::isPermitted($relation['related_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 assigning values to variables in if clauses and the like (line '37', column '8'). Open
public function process(App\Request $request)
{
$moduleName = $request->getModule();
$viewer = $this->getViewer($request);
if (Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission($request->getModule())) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The method process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$relations = $mail->findRelatedRecords();
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class 'App\Config' in method 'getModules'. Open
$quickCreate = App\Config::module('MailIntegration', 'modulesListQuickCreate', []);
- 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 "related_modulename" 4 times. Open
if (0 === $relation['presence'] && 'getRecordToMails' === $relation['name'] && App\Privilege::isPermitted($relation['related_modulename'])) {
- 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.
Argument 1 (mixed)
is string
but \Users_Privileges_Model::hasModulePermission()
takes int
defined at /code/modules/Users/models/Privileges.php:101
Open
if (Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission($request->getModule())) {
- Exclude checks
Call to undeclared method \MailIntegration_Iframe_View::checkAndConvertJsScripts
Open
return $this->checkAndConvertJsScripts([
- Exclude checks
Class extends undeclared class \App\Controller\Modal
Open
class MailIntegration_Iframe_View extends \App\Controller\Modal
- Exclude checks
Call to undeclared method \MailIntegration_Iframe_View::getViewer
Open
$viewer = $this->getViewer($request);
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class MailIntegration_Iframe_View extends \App\Controller\Modal
- Exclude checks
The class MailIntegration_Iframe_View is not named in CamelCase. Open
class MailIntegration_Iframe_View extends \App\Controller\Modal
{
/** {@inheritdoc} */
public $showHeader = false;
/** {@inheritdoc} */
- 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
return $modules;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return true;
- 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
public function process(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('MODULES', $this->getModules());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relations = $mail->getRelatedRecords();
- 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
'modules.Vtiger.resources.Edit',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getModules(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$quickCreate = App\Config::module('MailIntegration', 'modulesListQuickCreate', []);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $showFooter = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mail->initFromRequest($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->checkAndConvertJsScripts([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'~layouts/resources/validator/FieldValidator.js'
- 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 $showHeader = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get modules.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 === $relation['presence'] && 'getRecordToMails' === $relation['name'] && App\Privilege::isPermitted($relation['related_modulename'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'~layouts/resources/Field.js',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Line exceeds 120 characters; contains 153 characters Open
if (0 === $relation['presence'] && 'getRecordToMails' === $relation['name'] && App\Privilege::isPermitted($relation['related_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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mail = App\Mail\Message::getScannerByEngine($request->getByType('source'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('MODAL_SCRIPTS', $this->getModalScripts($request));
- 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 = [];
- Exclude checks
Line exceeds 120 characters; contains 132 characters Open
$quickCreateSupported = Vtiger_Module_Model::getInstance($relation['related_modulename'])->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
$quickCreateSupported = Vtiger_Module_Model::getInstance($relation['related_modulename'])->isQuickCreateSupported();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getModalScripts(App\Request $request)
- 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
if ($mailId = $mail->getMailCrmId()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relations = $mail->findRelatedRecords();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('MAIL_ID', $mailId);
- 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
'~layouts/resources/validator/BaseValidator.js',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('RELATIONS', $relations);
- 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
/** {@inheritdoc} */
- 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 (Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission($request->getModule())) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 161 characters Open
$modules[$relation['related_modulename']] = $quickCreateSupported && (!$quickCreate || \in_array($relation['related_modulename'], $quickCreate));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer = $this->getViewer($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('URL', App\Config::main('site_URL'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->view('Iframe/Container.tpl', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (\App\Relation::getByModule('OSSMailView', true) as $relation) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function checkPermission(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
"modules.{$request->getModule()}.resources.{$request->getByType('view', 2)}",
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules[$relation['related_modulename']] = $quickCreateSupported && (!$quickCreate || \in_array($relation['related_modulename'], $quickCreate));
- 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
$moduleName = $request->getModule();
- 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
Class name "MailIntegration_Iframe_View" is not in camel caps format Open
class MailIntegration_Iframe_View extends \App\Controller\Modal
- Exclude checks