app/Automatic/RulesPicklist.php
Function check
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
Open
protected function check(array $items, array $params): bool
{
$condition = $params['condition'] ?? '';
$b = false;
foreach ($params['rules'] as $rule) {
- 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 variables with short names like $b. Configured minimum length is 3. Open
Open
$b = false;
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$condition = $params['condition'] ?? '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $b;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$returnArr[] = $item['status'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param int $automation
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$automation = $rule[static::AUTOMATION] ?? -1;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param array $items
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if ('or' === $condition && $b) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if ('and' === $condition && !$b) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
foreach ($params['rules'] as $rule) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Filter the array and get only the status.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
protected function check(array $items, array $params): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
protected function filterItems(array $items, int $automation = -1): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $returnArr;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$b = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$val = $rule['value'] ?? '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (-1 === $automation || $item['automation'] === $automation) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* What value to choose from the plicklist for rules. -1 = All, 1 = Closed , 0 = Open.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$returnArr = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$b = $this->checkOperator($operator, $this->filterItems($items, $automation), $val);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public const AUTOMATION = 'automation';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$operator = $rule['operator'] ?? '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
foreach ($items as $item) {
- Exclude checks