src/Flow/Lexeme.php

Summary

Maintainability
A
1 hr
Test Coverage

Method syntax has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function syntax(string $key, array $data)
    {
        foreach ($data['directives'] ?? [] as $_key => $directive)
        {
            $this->data($_key, $directive ?: []);
Severity: Minor
Found in src/Flow/Lexeme.php - About 1 hr to fix

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

        protected function loader($file)
        {
            foreach ($this->folders as $folder)
            {
                foreach (FileLoader::extensions() as $ext)
    Severity: Minor
    Found in src/Flow/Lexeme.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

    Avoid using static access to class 'Bavix\Flow\Cache' in method 'tryLoad'.
    Open

                $item = Cache::getItem(__CLASS__ . $key);
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    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

    Avoid using static access to class 'Bavix\Flow\Cache' in method 'lexerApply'.
    Open

            return Cache::get($name, function () use ($store) {
                return $store;
            });
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    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

    Avoid using static access to class '\Bavix\Helpers\Arr' in method 'apply'.
    Open

                    $data = Arr::map($data, [$this, 'lexerApply']);
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    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

    Avoid using static access to class '\Bavix\SDK\FileLoader' in method 'loader'.
    Open

                foreach (FileLoader::extensions() as $ext)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    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

    Avoid using static access to class '\Bavix\Helpers\Arr' in method 'property'.
    Open

                    $extends = Arr::map((array)$prop['extends'], function ($extend) use ($self, &$props) {
                        return $self->property($props, $extend);
                    });
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    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

    Avoid using static access to class '\Bavix\Helpers\Arr' in method 'addFolder'.
    Open

            Arr::unShift($this->folders, $path);
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    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

    Avoid using static access to class 'Bavix\Flow\Property' in method '__construct'.
    Open

            $this->types = Property::get('types');
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    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

    Avoid using static access to class 'Bavix\Flow\Cache' in method 'lexerApply'.
    Open

            $item = Cache::getItem($name);
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    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

    Avoid using static access to class '\Bavix\SDK\FileLoader' in method 'loader'.
    Open

                        return FileLoader::load($folder . '/' . $file . '.' . $ext);
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    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

    Avoid using static access to class '\Bavix\Helpers\Arr' in method 'apply'.
    Open

                    $data = Arr::filter($outs, function (...$args) {
                        return \is_string(\end($args));
                    });
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    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

    Avoid using static access to class 'Bavix\Flow\Cache' in method 'syntax2Array'.
    Open

            return Cache::get(__CLASS__ . $key, function () use ($syntax, $props, $closed) {
                return [
                    'syntax' => $syntax,
                    'props'  => $props,
                    'closed' => $closed,
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    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 "syntax" 3 times.
    Open

                    'syntax' => $syntax,
    Severity: Critical
    Found in src/Flow/Lexeme.php by sonar-php

    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.

    Rename "$closed" which has the same name as the field declared at line 44.
    Open

            $closed = $this->closed[$key] ?? false;
    Severity: Major
    Found in src/Flow/Lexeme.php by sonar-php

    Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

    Noncompliant Code Example

    class Foo {
      public $myField;
    
      public function doSomething() {
        $myField = 0;
        ...
      }
    }
    

    See

    Rename "$data" which has the same name as the field declared at line 39.
    Open

            $data    = null;
    Severity: Major
    Found in src/Flow/Lexeme.php by sonar-php

    Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

    Noncompliant Code Example

    class Foo {
      public $myField;
    
      public function doSomething() {
        $myField = 0;
        ...
      }
    }
    

    See

    Rename "$props" which has the same name as the field declared at line 34.
    Open

            $props  = $this->props[$key] ?? null;
    Severity: Major
    Found in src/Flow/Lexeme.php by sonar-php

    Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

    Noncompliant Code Example

    class Foo {
      public $myField;
    
      public function doSomething() {
        $myField = 0;
        ...
      }
    }
    

    See

    Define a constant instead of duplicating this literal "types" 3 times.
    Open

            'types' => [
    Severity: Critical
    Found in src/Flow/Lexeme.php by sonar-php

    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.

    Define a constant instead of duplicating this literal "closed" 3 times.
    Open

                    'closed' => $closed,
    Severity: Critical
    Found in src/Flow/Lexeme.php by sonar-php

    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.

    Avoid unused local variables such as '$prop'.
    Open

            foreach ($props as $key => $prop)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    UnusedLocalVariable

    Since: 0.2

    Detects when a local variable is declared and/or assigned, but not used.

    Example

    class Foo {
        public function doSomething()
        {
            $i = 5; // Unused
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

    The closing brace for the class must go on the next line after the body
    Open

    }
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            foreach ($data['directives'] ?? [] as $_key => $directive)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            foreach ($data['syntax'] ?? [] as $text)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 13
    Open

                foreach (FileLoader::extensions() as $ext)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            if (null === $loader)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            if (!\array_key_exists($key, $this->data))
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            if ($loader)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after TRY keyword; newline found
    Open

                    try
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 13
    Open

                if ($item && $item->isHit())
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            foreach ($types as $type)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 17
    Open

                    catch (\Throwable $throwable)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            foreach ($lexData as $datum)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            foreach ($this->folders as $folder)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            if (empty($this->data[$key]))
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            if (!$this->lexer)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            if (empty($this->data[$key]))
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 13
    Open

                foreach ($vars as $var)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 13
    Open

                if (\is_object($mixed))
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            if (true === $lexData)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            foreach ($props as $key => $prop)
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            if (empty($this->props[$key]))
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing brace; newline found
    Open

                    }
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 13
    Open

                if (isset($prop['extends']))
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 9
    Open

            if ($item && $item->isHit())
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 13
    Open

                if (\preg_match($datum['regexp'], $tpl, $outs))
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpcodesniffer

    The variable $_lexer is not named in camelCase.
    Open

        public function lexerApply(string $value): array
        {
            $name = __FUNCTION__ . $value;
            $item = Cache::getItem($name);
    
    
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $_key is not named in camelCase.
    Open

        protected function syntax(string $key, array $data)
        {
            foreach ($data['directives'] ?? [] as $_key => $directive)
            {
                $this->data($_key, $directive ?: []);
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $_key is not named in camelCase.
    Open

        protected function syntax(string $key, array $data)
        {
            foreach ($data['directives'] ?? [] as $_key => $directive)
            {
                $this->data($_key, $directive ?: []);
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $_lexer is not named in camelCase.
    Open

        public function lexerApply(string $value): array
        {
            $name = __FUNCTION__ . $value;
            $item = Cache::getItem($name);
    
    
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $_cache is not named in camelCase.
    Open

        protected function tryLoad(string $key)
        {
            if (empty($this->data[$key]))
            {
                $item = Cache::getItem(__CLASS__ . $key);
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $_cache is not named in camelCase.
    Open

        protected function tryLoad(string $key)
        {
            if (empty($this->data[$key]))
            {
                $item = Cache::getItem(__CLASS__ . $key);
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $_cache is not named in camelCase.
    Open

        protected function tryLoad(string $key)
        {
            if (empty($this->data[$key]))
            {
                $item = Cache::getItem(__CLASS__ . $key);
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $_cache is not named in camelCase.
    Open

        protected function tryLoad(string $key)
        {
            if (empty($this->data[$key]))
            {
                $item = Cache::getItem(__CLASS__ . $key);
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $_lexer is not named in camelCase.
    Open

        public function lexerApply(string $value): array
        {
            $name = __FUNCTION__ . $value;
            $item = Cache::getItem($name);
    
    
    Severity: Minor
    Found in src/Flow/Lexeme.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    There are no issues that match your filters.

    Category
    Status