Method process
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
$recordId = $request->getInteger('id');
$workflowModel = Settings_Workflows_Record_Model::getInstance($recordId);
$workflowObject = $workflowModel->getWorkflowObject();
Function process
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
$recordId = $request->getInteger('id');
$workflowModel = Settings_Workflows_Record_Model::getInstance($recordId);
$workflowObject = $workflowModel->getWorkflowObject();
- 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 '26', column '14'). Open
$xml = new DOMDocument('1.0', 'utf-8');
- 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 process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$value = $workflowModel->get($field);
$xmlColumn = $xml->createElement($field, html_entity_decode($value, ENT_COMPAT, 'UTF-8'));
}
- 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 'Settings_Workflows_Record_Model' in method 'process'. Open
$workflowModel = Settings_Workflows_Record_Model::getInstance($recordId);
- 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
$method = Settings_Workflows_Module_Model::exportTaskMethod($taskObject->methodName);
- 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 "UTF-8" 7 times. Open
$xmlColumn = $xml->createElement($field, html_entity_decode($value, ENT_COMPAT, 'UTF-8'));
- 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.
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_Workflows_ExportWorkflow_Action extends Settings_Vtiger_Index_Action
- Exclude checks
The class Settings_Workflows_ExportWorkflow_Action is not named in CamelCase. Open
class Settings_Workflows_ExportWorkflow_Action extends Settings_Vtiger_Index_Action
{
public function process(App\Request $request)
{
$recordId = $request->getInteger('id');
- 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
$workflowObject = $workflowModel->getWorkflowObject();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlFields = $xml->createElement('fields');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif (isset($workflowObject->{$field})) {
- 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
$xmlTask = $xml->createElement('workflow_task');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$method = Settings_Workflows_Module_Model::exportTaskMethod($taskObject->methodName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\array_key_exists($method['workflowtasks_entitymethod_id'], $method)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($workflowMethods as $method) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('content-type: application/xml; charset=utf-8');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$name->appendChild($xml->createCDATASection(json_encode($workflowModel->get($field))));
- 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
$xmlFields->appendChild($xmlField);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlTemplate->appendChild($xmlFields);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlTemplate->appendChild($xmlTasks);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo $xml->saveXML();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function validateRequest(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
$xmlTemplate = $xml->createElement('workflow');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$name = $xmlField->appendChild($xml->createElement($field));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
require_once 'modules/com_vtiger_workflow/tasks/VTEntityMethodTask.php';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($workflowModel->has($field)) {
- 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
$xmlField->appendChild($xmlColumn);
- Exclude checks
Line exceeds 120 characters; contains 141 characters Open
$xmlMethod->appendChild($xml->createElement('function_path', html_entity_decode($method['function_path'], ENT_COMPAT, 'UTF-8')));
- 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
header('cache-control: private');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('content-disposition: attachment; filename="' . $recordId . '_workflow.xml"');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$cDataColumns = ['conditions'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $workflowModel->get($field);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlColumn = $xml->createElement($field, html_entity_decode($value, ENT_COMPAT, 'UTF-8'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlColumn = $xml->createElement('summary', html_entity_decode($task['summary'], ENT_COMPAT, 'UTF-8'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false !== strpos($task['task'], 'VTEntityMethodTask')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$script->appendChild($xml->createCDATASection(html_entity_decode($method['script_content'])));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlTemplate->appendChild($xmlMethods);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xml->appendChild($xmlTemplate);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $workflowObject->{$field};
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlTasks = $xml->createElement('workflow_tasks');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlTask->appendChild($xmlColumn);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$taskObject = unserialize(html_entity_decode($task['task']));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlMethod->appendChild($xml->createElement('function_path', html_entity_decode($method['function_path'], ENT_COMPAT, 'UTF-8')));
- Exclude checks
Line exceeds 120 characters; contains 141 characters Open
$xmlMethod->appendChild($xml->createElement('function_name', html_entity_decode($method['function_name'], ENT_COMPAT, 'UTF-8')));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$workflowModel = Settings_Workflows_Record_Model::getInstance($recordId);
- 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
$xml = new DOMDocument('1.0', 'utf-8');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlField = $xml->createElement('field');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (Settings_Workflows_Module_Model::$allFields as $field) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($workflowModel->getTasksForExport() as $task) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$workflowMethods[$method['workflowtasks_entitymethod_id']] = $method;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlMethods = $xml->createElement('workflow_methods');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlMethod = $xml->createElement('workflow_method');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$workflowMethods = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('pragma: public');
- 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
$script = $xmlMethod->appendChild($xml->createElement('script_content'));
- 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
$xml->formatOutput = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array($field, $cDataColumns)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$name->appendChild($xml->createCDATASection(base64_encode($task['task'])));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlMethod->appendChild($xml->createElement('method_name', html_entity_decode($method['method_name'], ENT_COMPAT, 'UTF-8')));
- Exclude checks
Line exceeds 120 characters; contains 137 characters Open
$xmlMethod->appendChild($xml->createElement('method_name', html_entity_decode($method['method_name'], ENT_COMPAT, 'UTF-8')));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlMethod->appendChild($xml->createElement('function_name', html_entity_decode($method['function_name'], ENT_COMPAT, 'UTF-8')));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlMethods->appendChild($xmlMethod);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xml->preserveWhiteSpace = false;
- 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
$request->validateReadAccess();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordId = $request->getInteger('id');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('content-description: PHP Generated Data');
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlColumn = $xml->createElement($field, html_entity_decode($value, ENT_COMPAT, 'UTF-8'));
- 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
$name = $xmlTask->appendChild($xml->createElement('task'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlTasks->appendChild($xmlTask);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlMethod->appendChild($xml->createElement('module_name', html_entity_decode($method['module_name'], ENT_COMPAT, 'UTF-8')));
- Exclude checks
Line exceeds 120 characters; contains 137 characters Open
$xmlMethod->appendChild($xml->createElement('module_name', html_entity_decode($method['module_name'], ENT_COMPAT, 'UTF-8')));
- Exclude checks
Class name "Settings_Workflows_ExportWorkflow_Action" is not in camel caps format Open
class Settings_Workflows_ExportWorkflow_Action extends Settings_Vtiger_Index_Action
- Exclude checks