Showing 264 of 264 total issues

Function buildWithoutCache has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

    public function buildWithoutCache(array $data): string
    {
        $code     = [];
        $lastLast = null;
        $last     = null;
Severity: Minor
Found in src/Flow/Flow.php - About 6 hrs 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

File Flow.php has 378 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Bavix\Flow;

use Bavix\Exceptions\Invalid;
Severity: Minor
Found in src/Flow/Flow.php - About 5 hrs to fix

    The class Flow has 12 public methods. Consider refactoring Flow to keep number of public methods under 10.
    Open

    class Flow
    {
    
        const VERSION = '1.0.6';
    
    
    Severity: Minor
    Found in src/Flow/Flow.php by phpmd

    TooManyPublicMethods

    Since: 0.1

    A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

    By default it ignores methods starting with 'get' or 'set'.

    Example

    Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

    The class Flow has an overall complexity of 79 which is very high. The configured complexity threshold is 50.
    Open

    class Flow
    {
    
        const VERSION = '1.0.6';
    
    
    Severity: Minor
    Found in src/Flow/Flow.php by phpmd

    Method buildWithoutCache has 82 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function buildWithoutCache(array $data): string
        {
            $code     = [];
            $lastLast = null;
            $last     = null;
    Severity: Major
    Found in src/Flow/Flow.php - About 3 hrs to fix

      Flow has 25 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Flow
      {
      
          const VERSION = '1.0.6';
      
      
      Severity: Minor
      Found in src/Flow/Flow.php - About 2 hrs to fix

        The class Flow has 19 fields. Consider redesigning Flow to keep the number of fields under 15.
        Open

        class Flow
        {
        
            const VERSION = '1.0.6';
        
        
        Severity: Minor
        Found in src/Flow/Flow.php by phpmd

        TooManyFields

        Since: 0.1

        Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

        Example

        class Person {
           protected $one;
           private $two;
           private $three;
           [... many more fields ...]
        }

        Source https://phpmd.org/rules/codesize.html#toomanyfields

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

            public function compile(string $view): string
            {
                $path      = $this->native()->path($view . $this->ext());
                $this->tpl = \file_get_contents($path);
                $tokens    = $this->lexer()->tokens($this->tpl);
        Severity: Minor
        Found in src/Flow/Flow.php - About 1 hr to fix

          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

            Method testExtends has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function testExtends()
                {
            
                    $codeWithoutComments = <<<code
                <h1>{{ message }}</h1>
            Severity: Minor
            Found in tests/Flow/Directives/MinifyTest.php - About 1 hr to fix

              Method testRaw has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function testRaw()
                  {
              
                      $code = <<<code
                  {{ message }}
              Severity: Minor
              Found in tests/Flow/Directives/RawTest.php - About 1 hr to fix

                Method testComments has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function testComments()
                    {
                
                        $code = <<<code
                        <!-- print message -->
                Severity: Minor
                Found in tests/Flow/Directives/MinifyTest.php - About 1 hr to fix

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

                          $a = 'hello';
                  Severity: Minor
                  Found in tests/Flow/Directives/DumpTest.php by phpmd

                  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

                  The class Flow has a coupling between objects value of 22. Consider to reduce the number of dependencies under 13.
                  Open

                  class Flow
                  {
                  
                      const VERSION = '1.0.6';
                  
                  
                  Severity: Minor
                  Found in src/Flow/Flow.php by phpmd

                  CouplingBetweenObjects

                  Since: 1.1.0

                  A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

                  Example

                  class Foo {
                      /**
                       * @var \foo\bar\X
                       */
                      private $x = null;
                  
                      /**
                       * @var \foo\bar\Y
                       */
                      private $y = null;
                  
                      /**
                       * @var \foo\bar\Z
                       */
                      private $z = null;
                  
                      public function setFoo(\Foo $foo) {}
                      public function setBar(\Bar $bar) {}
                      public function setBaz(\Baz $baz) {}
                  
                      /**
                       * @return \SplObjectStorage
                       * @throws \OutOfRangeException
                       * @throws \InvalidArgumentException
                       * @throws \ErrorException
                       */
                      public function process(\Iterator $it) {}
                  
                      // ...
                  }

                  Source https://phpmd.org/rules/design.html#couplingbetweenobjects

                  Consider simplifying this complex logical expression.
                  Open

                              if ($last && (!$lastLast ||
                                      ($lastLast->type !== T_VARIABLE &&
                                          $lastLast->type !== Validator::T_ENDBRACKET &&
                                          $lastLast->type !== Validator::T_ENDARRAY))
                                  && $last->type === Validator::T_DOT)
                  Severity: Major
                  Found in src/Flow/Flow.php - About 40 mins to fix

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

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

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

                    }

                    Function closing brace must go on the next line following the body; found 1 blank lines before brace
                    Open

                        }

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

                    }
                    Severity: Minor
                    Found in tests/Unit.php by phpcodesniffer

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

                        public function compile(string $view): string
                        {
                            $path      = $this->native()->path($view . $this->ext());
                            $this->tpl = \file_get_contents($path);
                            $tokens    = $this->lexer()->tokens($this->tpl);
                    Severity: Minor
                    Found in src/Flow/Flow.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

                    Severity
                    Category
                    Status
                    Source
                    Language