process accesses the super-global variable $_FILES. Open
public function process(App\Request $request)
{
\App\Log::trace('Start ' . __METHOD__);
$qualifiedModule = $request->getModule(false);
$viewer = $this->getViewer($request);
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
process accesses the super-global variable $_FILES. Open
public function process(App\Request $request)
{
\App\Log::trace('Start ' . __METHOD__);
$qualifiedModule = $request->getModule(false);
$viewer = $this->getViewer($request);
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
process accesses the super-global variable $_FILES. Open
public function process(App\Request $request)
{
\App\Log::trace('Start ' . __METHOD__);
$qualifiedModule = $request->getModule(false);
$viewer = $this->getViewer($request);
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
Function process
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
\App\Log::trace('Start ' . __METHOD__);
$qualifiedModule = $request->getModule(false);
$viewer = $this->getViewer($request);
- 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
Method process
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
\App\Log::trace('Start ' . __METHOD__);
$qualifiedModule = $request->getModule(false);
$viewer = $this->getViewer($request);
The method process() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
public function process(App\Request $request)
{
\App\Log::trace('Start ' . __METHOD__);
$qualifiedModule = $request->getModule(false);
$viewer = $this->getViewer($request);
- 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
Refactor this function to reduce its Cognitive Complexity from 38 to the 15 allowed. Open
public function process(App\Request $request)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Avoid using static access to class '\App\Log' in method 'process'. Open
\App\Log::trace('Start ' . __METHOD__);
- 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 'Settings_Workflows_Module_Model' in method 'process'. Open
$workflowModel = Settings_Workflows_Module_Model::getInstance('Settings:Workflows');
- 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
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 {
$viewer->assign('UPLOAD_ERROR', \App\Language::translate('LBL_UPLOAD_ERROR', $qualifiedModule));
$viewer->assign('UPLOAD', false);
}
- 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\Log' in method 'process'. Open
\App\Log::trace('End ' . __METHOD__);
- 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 'process'. Open
$viewer->assign('UPLOAD_ERROR', \App\Language::translate('LBL_UPLOAD_ERROR', $qualifiedModule));
- 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 "imported_xml" 3 times. Open
$xmlName = $_FILES['imported_xml']['name'];
- 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.
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('End ' . __METHOD__);
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('Start ' . __METHOD__);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('MESSAGES', $messages);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('UPLOAD_ERROR', \App\Language::translate('LBL_UPLOAD_ERROR', $qualifiedModule));
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('RECORDID', $messages['id']);
- Exclude checks
Suspicious array access to int
Open
$viewer->assign('RECORDID', $messages['id']);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('UPLOAD', true);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('QUALIFIED_MODULE', $qualifiedModule);
- Exclude checks
Return type of getHeaderCss()
is undeclared type \App\Controller\View\Vtiger_CssScript_Model[]
Open
public function getHeaderCss(App\Request $request)
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('UPLOAD', false);
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_Workflows_Import_View extends Settings_Vtiger_Index_View
- Exclude checks
The class Settings_Workflows_Import_View is not named in CamelCase. Open
class Settings_Workflows_Import_View extends Settings_Vtiger_Index_View
{
public function process(App\Request $request)
{
\App\Log::trace('Start ' . __METHOD__);
- 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
public function process(App\Request $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
\App\Log::trace('Start ' . __METHOD__);
- 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
foreach ($fieldsValue as $fieldKey => $fieldValue) {
- 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 ('workflow_task' === $fieldKey) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('UPLOAD', 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
$viewer->assign('QUALIFIED_MODULE', $qualifiedModule);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($request->has('upload') && 'true' == $request->get('upload')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xml = simplexml_load_file($uploadedXml);
- 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('UPLOAD', true);
- 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_merge($cssInstances, $headerCssInstances);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlError = $_FILES['imported_xml']['error'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$taskIndex = $methodIndex = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$columnKey = 'test';
- 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
$cssInstances = $this->checkAndConvertCssStyles($cssFileNames);
- 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
$qualifiedModule = $request->getModule(false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($fieldKey) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params[$fieldsKey][$taskIndex][$columnKey] = (string) $columnValue;
- 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('RECORDID', $messages['id']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getHeaderCss(App\Request $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
$uploadedXml = $_FILES['imported_xml']['tmp_name'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('UPLOAD_ERROR', \App\Language::translate('LBL_UPLOAD_ERROR', $qualifiedModule));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlName = $_FILES['imported_xml']['name'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$extension = end($explodeXmlName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$workflowModel = Settings_Workflows_Module_Model::getInstance('Settings:Workflows');
- 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
$explodeXmlName = explode('.', $xmlName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('type' == $columnKey && empty($columnValue)) {
- 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 (UPLOAD_ERR_OK == $xmlError && 'xml' === $extension) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('conditions' === $columnKey) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'workflow_method':
- 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
$params[$fieldsKey][$columnKey] = (string) $columnValue;
- 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
++$taskIndex;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('MESSAGES', $messages);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$columnValue = 'basic';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'workflow_task':
- 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
foreach ($xml as $fieldsKey => $fieldsValue) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params[$fieldsKey][$methodIndex][$columnKey] = (string) $columnValue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('workflow_method' === $fieldKey) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
++$methodIndex;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->view('Import.tpl', $qualifiedModule);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::trace('End ' . __METHOD__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$headerCssInstances = parent::getHeaderCss($request);
- 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
foreach ($fieldValue as $columnKey => $columnValue) {
- 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
$messages = $workflowModel->importWorkflow($params);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$cssFileNames = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
"modules.Settings.$moduleName.Import",
- Exclude checks
Class name "Settings_Workflows_Import_View" is not in camel caps format Open
class Settings_Workflows_Import_View extends Settings_Vtiger_Index_View
- Exclude checks