app/Conditions/QueryFields/MultipicklistField.php
Function getCombinations
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
Open
public function getCombinations($array, $tempString = '')
{
$countArray = \count($array);
$result = '';
for ($i = 0; $i < $countArray; ++$i) {
- 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 getCombinations uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
Open
} else {
return [$tempString . $this->separator . $element[0]];
}
- 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
Spaces must be used to indent lines; tabs are not allowed Open
Open
$valueArray = explode('##', $value);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Not equal 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
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function getCombinations($array, $tempString = '')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$element = array_splice($splicedArray, $i, 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
array_push($condition, [$this->getColumnName() => $value], ['or like', $this->getColumnName(),
- 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
"{$value}{$this->separator}%",
- 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
* @return array
- 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 $array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $tempString
- 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
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
"{$value}{$this->separator}%",
- 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
$condition = ['and'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
"%{$this->separator}{$value}{$this->separator}%",
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
protected $separator = ' |##| ';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$result = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
} else {
- 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
* Contains 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
]);
- 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
return [$tempString . $this->separator . $element[0]];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return mixed
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$value = $this->value;
- 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
Line exceeds 120 characters; contains 132 characters Open
Open
$result = array_merge($result, $this->getCombinations($splicedArray, $tempString . $this->separator . $element[0]));
- 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
return $result;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
"%{$this->separator}{$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
$result = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (!\is_array($result)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$result = array_merge($result, $this->getCombinations($splicedArray, $tempString . $this->separator . $element[0]));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$valueArray[$key] = ltrim($value, $this->separator);
- 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
return ['not', [$this->getColumnName() => $this->getValue()]];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
"%{$this->separator}{$value}{$this->separator}%",
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
foreach ($this->getValue() as $value) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/** @var string Separator. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
for ($i = 0; $i < $countArray; ++$i) {
- 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
return $valueArray;
- 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
* Does not contain operator.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function operatorK(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
"%{$this->separator}{$value}",
- 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
* Function to get combinations of string from Array.
- 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 ($this->getValue() as $value) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
], false,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
], false,
- 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 function operatorN(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
array_push($condition, ['<>', $this->getColumnName(), $value], ['not', ['or like', $this->getColumnName(),
- 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
$condition = ['or'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$countArray = \count($array);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$splicedArray = $array;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $condition;
- 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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (\count($splicedArray) > 0) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function getValue()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (\in_array($this->operator, ['e', 'n'])) {
- 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
* Get value.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
foreach ($this->getCombinations($valueArray) as $key => $value) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function operatorC(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $condition;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks