Function check
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function check(array $items, array $params): bool
{
$condition = $params['condition'] ?? '';
$returnVal = 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
The method __construct has a boolean flag argument $defaultValue, which is a certain sign of a Single Responsibility Principle violation. Open
public function __construct(array $config, $defaultValue = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '146', column '13'). Open
throw new \App\Exceptions\IllegalValue("ERR_NOT_ALLOWED_VALUE||$operator", 406);
- 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 assigning values to variables in if clauses and the like (line '139', column '7'). Open
protected function checkOperator(string $operator, array $items, $val): bool
{
if ($negation = $this->isNegation($operator)) {
$operator = \substr($operator, 3, \strlen($operator) - 3);
}
- 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 variables with short names like $b. Configured minimum length is 3. Open
$b = !empty($items);
- 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
public const CONDITION_ALL_RECORDS_EQUAL = 'allRecordsEqual';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check if the elements of the input array are not equal to the value.
- 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 ($this->config as $key => $params) {
- 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
* @param mixed $valueOfCondition
- 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 mixed $valueOfCondition
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check if the value in the input array does not exist.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const CONDITION_ONLY_CONTAINS = 'onlyContains';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->check($items, $params)) {
- 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 $returnVal;
- 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
$returnVal = $this->checkOperator($rule['operator'] ?? '', $items, $rule['value'] ?? '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $operator
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$methodName = 'operator' . ucfirst($operator);
- 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
protected function operatorIsExist(array $items, $valueOfCondition): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const CONDITION_NOT_ONLY_CONTAINS = 'notOnlyContains';
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $items
- 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
throw new \App\Exceptions\IllegalValue("ERR_NOT_ALLOWED_VALUE||$operator", 406);
- 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
* Check condition only contains.
- 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
return $b;
- 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
$returnVal = $this->defaultValue;
- 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
$returnVal = 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
$operator = \substr($operator, 3, \strlen($operator) - 3);
- 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
* Check if the elements of the input array are equal to the value.
- 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
* Check if the input array is not empty.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const CONDITION_NOT_NO_RECORDS = 'notNoRecords';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var mixed
- 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
* Get value.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getValue(array $items)
- 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
protected function check(array $items, array $params): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($params['rules'] as $rule) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\method_exists($this, $methodName)) {
- 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
/**
- 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
* @param mixed $val
- 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
* @param mixed $valueOfCondition
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->defaultValue = $defaultValue;
- 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
protected function checkOperator(string $operator, array $items, $val): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check if there is a negation operator.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check the condition all are equal.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected function operatorAllRecordsEqual(array $items, $valueOfCondition): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($val !== $valueOfCondition) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check the condition that the array is empty.
- 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
public const CONDITION_NO_RECORDS = 'noRecords';
- 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
$returnVal = $key;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('or' === $condition && $returnVal) {
- 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
private function isNegation(string $operator): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return \strlen($operator) >= 3 && 'not' === \substr($operator, 0, 3);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $items
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check the condition if it exists in the array.
- 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
public const CONDITION_NOT_IS_EXIST = 'notIsExist';
- 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
* Check if the input array is empty.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $config = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->config = $config;
- 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
* @return bool
- 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
* @return bool
- 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
* Check if the value in the input array exists.
- 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
/**
- 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 mixed
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Constructor.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $items
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check rules.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($negation = $this->isNegation($operator)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $returnVal;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check the condition.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($items as $val) {
- 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
/**
- 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
* Check the input array contains values.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* The default value is returned if the rules do not specify this case.
- 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 array $items
- 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 array $params
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$condition = $params['condition'] ?? '';
- 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
break;
- 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
* @param array $items
- 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 array $items
- 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 empty($items);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const CONDITION_IS_EXIST = 'isExist';
- 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 array $config
- 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
return $negation ? !$this->{$methodName}($items, $val) : $this->{$methodName}($items, $val);
- 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
protected function operatorOnlyContains(array $items, $valueOfCondition): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$arrU = array_unique($items);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$b = !empty($items);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $items
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const CONDITION_NOT_ALL_RECORDS_EQUAL = 'notAllRecordsEqual';
- 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
* Rules configuration.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var array
- 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 function __construct(array $config, $defaultValue = 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
* @return bool
- 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 bool
- 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
private $defaultValue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $defaultValue
- 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 ('and' === $condition && !$returnVal) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $operator
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check the input array does not contain values.
- 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
/**
- 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
return empty(array_diff($arrU, $valueOfCondition)) && empty(array_diff($valueOfCondition, $arrU));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return \in_array($valueOfCondition, $items);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$b = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- 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
protected function operatorNoRecords(array $items): bool
- Exclude checks