Method getTreeWorkflows
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getTreeWorkflows(string $moduleName, int $recordId): array
{
\Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');
$tree = [];
$workflowModuleName = 'Settings:Workflows';
Function getTreeWorkflows
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function getTreeWorkflows(string $moduleName, int $recordId): array
{
\Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');
$tree = [];
$workflowModuleName = 'Settings:Workflows';
- 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 execute
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function execute(string $moduleName, int $record, $userId, array $actions = [])
{
\Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');
$recordModel = \Vtiger_Record_Model::getInstanceById($record, $moduleName);
if ($userId) {
- 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 '30', column '15'). Open
$wfs = new VTWorkflowManager();
- 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 '56', column '22'). Open
$workflows = (new VTWorkflowManager())->getWorkflowsForModule($moduleName, VTWorkflowManager::$TRIGGER);
- 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_Loader' in method 'getTreeWorkflows'. Open
\Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');
- 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\Json' in method 'execute'. Open
if (!$workflow->params || !($params = \App\Json::decode($workflow->params)) || empty($params['showTasks']) || empty($params['enableTasks'])) {
- 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_Record_Model' in method 'getTreeWorkflows'. Open
$workflowRecord = Settings_Workflows_Record_Model::getInstanceFromWorkflowObject($workflow);
- 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 'getTreeWorkflows'. Open
'text' => ' ' . \App\Language::translate($task->getTaskObject()->summary, $workflowModuleName),
- 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_Record_Model' in method 'getTreeWorkflows'. Open
$recordModel = Vtiger_Record_Model::getInstanceById($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 '\App\Language' in method 'getTreeWorkflows'. Open
'text' => ' ' . \App\Language::translate($workflow->description, $workflowModuleName),
- 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 '34', column '34'). Open
public static function execute(string $moduleName, int $record, $userId, array $actions = [])
{
\Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');
$recordModel = \Vtiger_Record_Model::getInstanceById($record, $moduleName);
if ($userId) {
- 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
Avoid using static access to class '\Vtiger_Loader' in method 'execute'. Open
\Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');
- 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\Json' in method 'getTreeWorkflows'. Open
$params = $workflow->params ? \App\Json::decode($workflow->params) : [];
- 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_Record_Model' in method 'execute'. Open
$recordModel = \Vtiger_Record_Model::getInstanceById($record, $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 "category" 4 times. Open
'type' => 'category',
- 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 \Workflow->id
Open
'record_id' => $workflow->id,
- Exclude checks
Reference to undeclared property \Workflow->params
Open
$params = $workflow->params ? \App\Json::decode($workflow->params) : [];
- Exclude checks
Reference to undeclared property \Workflow->description
Open
'text' => ' ' . \App\Language::translate($workflow->description, $workflowModuleName),
- Exclude checks
Argument 2 (executionCondition)
is int
but \VTWorkflowManager::getWorkflowsForModule()
takes false|string
defined at /code/modules/com_vtiger_workflow/VTWorkflowManager.php:180
Open
$workflows = (new VTWorkflowManager())->getWorkflowsForModule($moduleName, VTWorkflowManager::$TRIGGER);
- Exclude checks
Reference to instance property params
from undeclared class \A
Open
if (!$workflow->params || !($params = \App\Json::decode($workflow->params)) || empty($params['showTasks']) || empty($params['enableTasks'])) {
- Exclude checks
Call to method performTasks
from undeclared class \A
Open
$workflow->performTasks($recordModel, $tasks);
- Exclude checks
Reference to undeclared property \Workflow->id
Open
'id' => $workflow->id,
- Exclude checks
Reference to undeclared property \Vtiger_Record_Model->executeUser
Open
$recordModel->executeUser = $userId;
- Exclude checks
Call to method evaluate
from undeclared class \A
Open
if ($workflow->evaluate($recordModel)) {
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Vtiger_WorkflowTrigger_Model
- Exclude checks
The class Vtiger_WorkflowTrigger_Model is not named in CamelCase. Open
class Vtiger_WorkflowTrigger_Model
{
/**
* Function executes workflow tasks.
*
- 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
Expected 0 spaces before opening brace; 1 found 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 (!$workflow->evaluate($recordModel)) {
- 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
'record_id' => $task->getId(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'parent' => $workflowRecord->getId(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'category' => ['checked' => false]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($actions as $id => $tasks) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$workflow = $wfs->retrieve($id);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = Vtiger_Record_Model::getInstanceById($recordId);
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $userId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = \Vtiger_Record_Model::getInstanceById($record, $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
foreach ($workflows as $workflow) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$workflowRecord = Settings_Workflows_Record_Model::getInstanceFromWorkflowObject($workflow);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'id' => ++$index,
- 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 $tree;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tree = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function execute(string $moduleName, int $record, $userId, array $actions = [])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($workflow->evaluate($recordModel)) {
- 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
'record_id' => $workflow->id,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'state' => ['selected' => false, 'disabled' => false, 'loaded' => true, 'opened' => false],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params = $workflow->params ? \App\Json::decode($workflow->params) : [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => 'category',
- 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 executes workflow tasks.
- 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
$workflow->performTasks($recordModel, $tasks);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tasks = null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'parent' => '#',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'state' => ['selected' => false, 'disabled' => empty($params['enableTasks'])],
- 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
'category' => ['checked' => 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
* @param int $record
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Line exceeds 120 characters; contains 158 characters Open
if (!$workflow->params || !($params = \App\Json::decode($workflow->params)) || empty($params['showTasks']) || empty($params['enableTasks'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'attr' => 'task',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->executeUser = $userId;
- 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
$index = max(array_column($workflows, '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
if (empty($params['showTasks'])) {
- 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 int $recordId
- 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
'attr' => '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
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$wfs = new VTWorkflowManager();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$workflows = (new VTWorkflowManager())->getWorkflowsForModule($moduleName, VTWorkflowManager::$TRIGGER);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => 'category',
- 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
$tree[] = [
- 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
$workflowModuleName = 'Settings:Workflows';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'text' => ' ' . \App\Language::translate($workflow->description, $workflowModuleName),
- 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
public static function getTreeWorkflows(string $moduleName, int $recordId): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tree[] = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'id' => $workflow->id,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($userId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$workflow->params || !($params = \App\Json::decode($workflow->params)) || empty($params['showTasks']) || empty($params['enableTasks'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($workflowRecord->getTasks() as $task) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $actions
- 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
\Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Gets workflow action tree.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'text' => ' ' . \App\Language::translate($task->getTaskObject()->summary, $workflowModuleName),
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 1 Open
class Vtiger_WorkflowTrigger_Model
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 1 Open
}
- Exclude checks
Class name "Vtiger_WorkflowTrigger_Model" is not in camel caps format Open
class Vtiger_WorkflowTrigger_Model
- Exclude checks