YetiForceCompany/YetiForceCRM

View on GitHub
modules/com_vtiger_workflow/expression_engine/VTTokenizer.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

Method __construct has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function __construct($expr)
    {
        $tokenTypes = [
            'SPACE' => ['\s+', 'processTokenId'],
            'SYMBOL' => ['[a-zA-Z][\w]*', 'processTokenSymbol'],
Severity: Minor
Found in modules/com_vtiger_workflow/expression_engine/VTTokenizer.php - About 1 hr to fix

    Missing class import via use statement (line '41', column '20').
    Open

            $this->EOF = new VTExpressionToken('EOF');

    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

    Missing class import via use statement (line '63', column '16').
    Open

            $token = new VTExpressionToken($tokenName);

    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

    Missing class import via use statement (line '86', column '14').
    Open

            return new VTEXpressionSymbol($token);

    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 nextToken uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $token->value = $this->tokenTypes[$tokenName][1]($match[$i]);
            }

    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

    Avoid using static access to class 'App\Purifier' in method '__construct'.
    Open

            preg_match_all($tokenRe, App\Purifier::decodeHtml($expr), $matches, PREG_SET_ORDER);

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Define a constant instead of duplicating this literal "processTokenSymbol" 6 times.
    Open

                'SYMBOL' => ['[a-zA-Z][\w]*', 'processTokenSymbol'],

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Reference to undeclared property \VTExpressionToken->value
    Open

                $token->value = \call_user_func([$this, $this->tokenTypes[$tokenName][1]], $match[$i]);

    Reference to undeclared property \VTExpressionTokenizer->tokenTypes (Did you mean $tokenTypes)
    Open

            $this->tokenTypes = $tokenTypes;

    Reference to undeclared property \VTExpressionTokenizer->EOF
    Open

                return $this->EOF;

    Reference to undeclared property \VTExpressionTokenizer->tokenNames
    Open

            $tokenName = $this->tokenNames[$i - 1];

    Reference to undeclared property \VTExpressionTokenizer->EOF
    Open

            $this->EOF = new VTExpressionToken('EOF');

    Reference to undeclared property \VTExpressionTokenizer->tokenTypes
    Open

                $token->value = $this->tokenTypes[$tokenName][1]($match[$i]);

    Reference to undeclared property \VTExpressionTokenizer->tokenNames (Did you mean $tokenNames)
    Open

            $this->tokenNames = $tokenNames;

    Reference to undeclared property \VTExpressionTokenizer->tokenTypes
    Open

                $token->value = \call_user_func([$this, $this->tokenTypes[$tokenName][1]], $match[$i]);

    Reference to undeclared property \VTExpressionTokenizer->idx (Did you mean $idx)
    Open

            $this->idx = $idx + 1;

    Reference to undeclared property \VTExpressionTokenizer->idx
    Open

            $this->idx = 0;

    Reference to undeclared property \VTExpressionTokenizer->matches
    Open

            $matches = $this->matches;

    Reference to undeclared property \VTExpressionToken->value
    Open

                $token->value = $this->tokenTypes[$tokenName][1]($match[$i]);

    Reference to undeclared property \VTExpressionTokenizer->idx
    Open

            $idx = $this->idx;

    Reference to undeclared property \VTExpressionTokenizer->tokenTypes
    Open

            if (method_exists($this, $this->tokenTypes[$tokenName][1])) {

    Reference to undeclared property \VTExpressionTokenizer->matches (Did you mean $matches)
    Open

            $this->matches = $matches;

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            $tokenTypes = [
                'SPACE' => ['\s+', 'processTokenId'],
                'SYMBOL' => ['[a-zA-Z][\w]*', 'processTokenSymbol'],
                'ESCAPED_SYMBOL' => ['?:`([^`]+)`', 'processTokenSymbol'],
                //"STRING" => array('?:(?:"((?:\\\\"|[^"])+)"|'."'((?:\\\\'|[^'])+)')", 'stripcslashes'),
    modules/ServiceContracts/ServiceContracts.php on lines 55..68

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 122.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    class VTExpressionTokenizer

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

            $i = 1;

    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 $re. Configured minimum length is 3.
    Open

                [$re] = $code;

    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

                'ESCAPED_SYMBOL' => ['?:`([^`]+)`', 'processTokenSymbol'],

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

                'FLOAT' => ['\d+[.]\d+', 'floatval'],

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

            $match = $matches[$idx];

    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->EOF = new VTExpressionToken('EOF');

    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

                $token->value = \call_user_func([$this, $this->tokenTypes[$tokenName][1]], $match[$i]);

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

            $this->processTokenId($token);

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

                'OPERATOR' => ['[+]|[-]|[*]|>=|<=|[<]|[>]|==|\/', 'processTokenSymbol'],

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

            $tokenNames = [];

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

            foreach ($tokenTypes as $tokenName => $code) {

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

                [$re] = $code;

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

            return $token;

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

                'SPACE' => ['\s+', 'processTokenId'],

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

                //"STRING" => array('?:"((?:\\\\"|[^"])+)"', 'stripcslashes'),

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

                'OPEN_BRACKET' => ['[(]', 'processTokenSymbol'],

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

                'CLOSE_BRACKET' => ['[)]', 'processTokenSymbol'],

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

        public function nextToken()

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

                return $this->EOF;

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

            }

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

                $token->value = $this->tokenTypes[$tokenName][1]($match[$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

                'SYMBOL' => ['[a-zA-Z][\w]*', 'processTokenSymbol'],

    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 ($idx == \count($matches)) {

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

            return new VTEXpressionSymbol($token);

    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 __construct($expr)

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

                'COMMA' => ['[,]', 'processTokenSymbol'],

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

                $tokenReArr[] = '(' . $re . ')';

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

            $matches = [];

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

            $matches = $this->matches;

    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 processTokenSymbol($token)

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

                'INTEGER' => ['\d+', 'intval'],

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

            $this->matches = $matches;

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

            if (method_exists($this, $this->tokenTypes[$tokenName][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

            $tokenTypes = [

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

        {

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

                'STRING' => ["?:'((?:\\\\'|[^'])+)'", 'stripcslashes'],

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

            $this->tokenTypes = $tokenTypes;

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

                $tokenNames[] = $tokenName;

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

            $tokenRe = '/' . implode('|', $tokenReArr) . '/';

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

            $idx = $this->idx;

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

            $this->idx = $idx + 1;

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

        private function processTokenId($token)

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

            return $token;

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

        }

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

                //"STRING" => array('?:(?:"((?:\\\\"|[^"])+)"|'."'((?:\\\\'|[^'])+)')", 'stripcslashes'),

    Line exceeds 120 characters; contains 129 characters
    Open

                // NOTE: Any new Operator added should be updated in VTParser.inc::$precedence and operation at VTExpressionEvaluater

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

            $this->tokenNames = $tokenNames;

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

            $tokenName = $this->tokenNames[$i - 1];

    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

                // NOTE: Any new Operator added should be updated in VTParser.inc::$precedence and operation at VTExpressionEvaluater

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

            ];

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

            $tokenReArr = [];

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

            preg_match_all($tokenRe, App\Purifier::decodeHtml($expr), $matches, PREG_SET_ORDER);

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

        public function tests($token)

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

            $this->idx = 0;

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

            $i = 1;

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

            $this->processTokenSymbol($token);

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

            while (empty($match[$i])) {

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

                ++$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

            $token = new VTExpressionToken($tokenName);

    There are no issues that match your filters.

    Category
    Status