YetiForceCompany/YetiForceCRM

View on GitHub
app/Conditions/QueryFields/MultipicklistField.php

Summary

Maintainability
A
35 mins
Test Coverage
F
0%

Function getCombinations has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function getCombinations($array, $tempString = '')
    {
        $countArray = \count($array);
        $result = '';
        for ($i = 0; $i < $countArray; ++$i) {
Severity: Minor
Found in app/Conditions/QueryFields/MultipicklistField.php - About 35 mins to fix

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

            } else {
                return [$tempString . $this->separator . $element[0]];
            }

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

        $valueArray = explode('##', $value);

Spaces must be used to indent lines; tabs are not allowed
Open

     * Not equal operator.

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getCombinations($array, $tempString = '')

Spaces must be used to indent lines; tabs are not allowed
Open

            $element = array_splice($splicedArray, $i, 1);

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

            array_push($condition, [$this->getColumnName() => $value], ['or like', $this->getColumnName(),

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

                    "{$value}{$this->separator}%",

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

                }

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param array  $array

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param string $tempString

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array

Spaces must be used to indent lines; tabs are not allowed
Open

                    "{$value}{$this->separator}%",

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

        $condition = ['and'];

Spaces must be used to indent lines; tabs are not allowed
Open

                    "%{$this->separator}{$value}{$this->separator}%",

Spaces must be used to indent lines; tabs are not allowed
Open

    protected $separator = ' |##| ';

Spaces must be used to indent lines; tabs are not allowed
Open

                    $result = [];

Spaces must be used to indent lines; tabs are not allowed
Open

            } else {

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     * Contains operator.

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

            ]);

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

                return [$tempString . $this->separator . $element[0]];

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return mixed

Spaces must be used to indent lines; tabs are not allowed
Open

        $value = $this->value;

Spaces must be used to indent lines; tabs are not allowed
Open

            }

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Line exceeds 120 characters; contains 132 characters
Open

                $result = array_merge($result, $this->getCombinations($splicedArray, $tempString . $this->separator . $element[0]));

Spaces must be used to indent lines; tabs are not allowed
Open

            }

Spaces must be used to indent lines; tabs are not allowed
Open

        return $result;

Spaces must be used to indent lines; tabs are not allowed
Open

                    "%{$this->separator}{$value}",

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array

Spaces must be used to indent lines; tabs are not allowed
Open

        $result = '';

Spaces must be used to indent lines; tabs are not allowed
Open

                if (!\is_array($result)) {

Spaces must be used to indent lines; tabs are not allowed
Open

                $result = array_merge($result, $this->getCombinations($splicedArray, $tempString . $this->separator . $element[0]));

Spaces must be used to indent lines; tabs are not allowed
Open

                $valueArray[$key] = ltrim($value, $this->separator);

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        return ['not', [$this->getColumnName() => $this->getValue()]];

Spaces must be used to indent lines; tabs are not allowed
Open

                    "%{$this->separator}{$value}{$this->separator}%",

Spaces must be used to indent lines; tabs are not allowed
Open

        foreach ($this->getValue() as $value) {

Spaces must be used to indent lines; tabs are not allowed
Open

    /** @var string Separator. */

Spaces must be used to indent lines; tabs are not allowed
Open

        for ($i = 0; $i < $countArray; ++$i) {

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

        return $valueArray;

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

                [

Spaces must be used to indent lines; tabs are not allowed
Open

     * Does not contain operator.

Spaces must be used to indent lines; tabs are not allowed
Open

    public function operatorK(): array

Spaces must be used to indent lines; tabs are not allowed
Open

                    "%{$this->separator}{$value}",

Spaces must be used to indent lines; tabs are not allowed
Open

            ]]);

Spaces must be used to indent lines; tabs are not allowed
Open

     * Function to get combinations of string from Array.

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        foreach ($this->getValue() as $value) {

Spaces must be used to indent lines; tabs are not allowed
Open

                ], false,

Spaces must be used to indent lines; tabs are not allowed
Open

                ], false,

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    public function operatorN(): array

Spaces must be used to indent lines; tabs are not allowed
Open

            array_push($condition, ['<>', $this->getColumnName(), $value], ['not', ['or like', $this->getColumnName(),

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

                [

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        $condition = ['or'];

Spaces must be used to indent lines; tabs are not allowed
Open

        $countArray = \count($array);

Spaces must be used to indent lines; tabs are not allowed
Open

            $splicedArray = $array;

Spaces must be used to indent lines; tabs are not allowed
Open

        return $condition;

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

            if (\count($splicedArray) > 0) {

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getValue()

Spaces must be used to indent lines; tabs are not allowed
Open

        if (\in_array($this->operator, ['e', 'n'])) {

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

     * Get value.

Spaces must be used to indent lines; tabs are not allowed
Open

            foreach ($this->getCombinations($valueArray) as $key => $value) {

Spaces must be used to indent lines; tabs are not allowed
Open

    public function operatorC(): array

Spaces must be used to indent lines; tabs are not allowed
Open

        return $condition;

Spaces must be used to indent lines; tabs are not allowed
Open

    }

There are no issues that match your filters.

Category
Status