YetiForceCompany/YetiForceCRM

View on GitHub
modules/com_vtiger_workflow/VTConditionalParser.php

Summary

Maintainability
A
25 mins
Test Coverage
F
0%

Function parse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function parse()
    {
        $op = [
            'and' => ['op', 'and'],
            'or' => ['op', 'or'],
Severity: Minor
Found in modules/com_vtiger_workflow/VTConditionalParser.php - About 25 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

Missing class import via use statement (line '53', column '15').
Open

                throw new VTParseFailed();

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

The method getTokens uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $tokenType = 'sym';
            }

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

The method parse uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $left = $this->cond();
        }

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

Reference to undeclared property \VTConditionalParser->pos
Open

        $this->pos = 0;

Reference to undeclared property \VTConditionalParser->pos
Open

        return $this->tokens[$this->pos];

Reference to undeclared property \VTConditionalParser->tokens
Open

        return $this->tokens[$this->pos];

Reference to undeclared property \VTConditionalParser->tokens
Open

        $this->tokens = $this->getTokens($expr);

Reference to undeclared property \VTConditionalParser->pos
Open

        ++$this->pos;

Reference to undeclared property \VTConditionalParser->pos
Open

        return $this->tokens[$this->pos - 1];

Reference to undeclared property \VTConditionalParser->pos
Open

        if (\count($this->tokens) > $this->pos && \in_array($this->peek(), [$op['and'], $op['or']])) {

Reference to undeclared property \VTConditionalParser->tokens
Open

        if (\count($this->tokens) > $this->pos && \in_array($this->peek(), [$op['and'], $op['or']])) {

Reference to undeclared property \VTConditionalParser->tokens
Open

        return $this->tokens[$this->pos - 1];

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class VTConditionalParser

Avoid variables with short names like $nt. Configured minimum length is 3.
Open

            $nt = $this->nextToken();

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

Avoid variables with short names like $op. Configured minimum length is 3.
Open

        $op = [

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

    {

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

    }

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

        $this->tokens = $this->getTokens($expr);

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

        $tokens = [];

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

    private function getTokens($expression)

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

            $tokenVal = $arr[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

            if (\in_array($tokenVal, ['and', 'or', '=', '(', ')'])) {

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

    public function __construct($expr)

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

        $this->pos = 0;

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

        foreach ($matches as $arr) {

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

    {

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

        preg_match_all('/and|or|\\d+|=|\\w+|\\(|\\)/', $expression, $matches, PREG_SET_ORDER);

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

        }

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

            $left = $this->cond();

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

        if (\count($this->tokens) > $this->pos && \in_array($this->peek(), [$op['and'], $op['or']])) {

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

    }

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

    private function nextToken()

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 ($this->peek() == $op['(']) {

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 $left;

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

        $operator = $this->nextToken();

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

    private function cond()

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 parse()

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

            'and' => ['op', 'and'],

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

            } else {

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

            $nt = $this->nextToken();

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

            return [$nt[1], $left, $this->parse()];

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

            $tokens[] = [$tokenType, $tokenVal];

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

        }

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

        $left = $this->nextToken();

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

            } elseif (is_numeric($tokenVal)) {

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

                $tokenType = 'num';

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

            '=' => ['op', '='],

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

            '(' => ['op', '('],

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

        return $this->tokens[$this->pos];

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

            $left = $this->parse();

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

        ++$this->pos;

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

        $op = [

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

                $tokenType = 'op';

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

            $this->nextToken();

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

            if ($this->nextToken() != $op[')']) {

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

        return [$operator[1], $left, $right];

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

    }

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

                $tokenType = 'sym';

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

        return $tokens;

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

    private function peek()

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

        return $this->tokens[$this->pos - 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

            'or' => ['op', 'or'],

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

            ')' => ['op', ')'], ];

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

                throw new VTParseFailed();

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

        $right = $this->nextToken();

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

    }

There are no issues that match your filters.

Category
Status