felixarntz/plugin-lib

View on GitHub
src/db-objects/view-routing.php

Summary

Maintainability
F
5 days
Test Coverage

Function get_model_permalink has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

        public function get_model_permalink( $model ) {
            if ( method_exists( $this->manager, 'get_status_property' ) ) {
                $status_property = $this->manager->get_status_property();
                if ( ! in_array( $model->$status_property, $this->manager->statuses()->get_public(), true ) ) {
                    return '';
Severity: Minor
Found in src/db-objects/view-routing.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 view-routing.php has 446 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * View_Routing manager class
 *
 * @package Leaves_And_Love\Plugin_Lib
Severity: Minor
Found in src/db-objects/view-routing.php - About 6 hrs to fix

    Function get_model_sample_permalink_for_property has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

            public function get_model_sample_permalink_for_property( $model, $property = '' ) {
                if ( '' === (string) get_option( 'permalink_structure' ) ) {
                    return '';
                }
    
    
    Severity: Minor
    Found in src/db-objects/view-routing.php - About 4 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

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

        abstract class View_Routing extends Service {
            use Container_Service_Trait, Hooks_Trait;
    
            /**
             * The base string to use.
    Severity: Minor
    Found in src/db-objects/view-routing.php by phpmd

    View_Routing has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

        abstract class View_Routing extends Service {
            use Container_Service_Trait, Hooks_Trait;
    
            /**
             * The base string to use.
    Severity: Minor
    Found in src/db-objects/view-routing.php - About 2 hrs to fix

      Function get_query_params has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

              protected function get_query_params( $query_vars ) {
                  $number        = $this->per_page;
                  $offset        = ( $this->paged - 1 ) * $number;
                  $no_found_rows = $this->is_singular() ? true : false;
      
      
      Severity: Minor
      Found in src/db-objects/view-routing.php - About 2 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

      Method get_model_permalink has 50 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              public function get_model_permalink( $model ) {
                  if ( method_exists( $this->manager, 'get_status_property' ) ) {
                      $status_property = $this->manager->get_status_property();
                      if ( ! in_array( $model->$status_property, $this->manager->statuses()->get_public(), true ) ) {
                          return '';
      Severity: Minor
      Found in src/db-objects/view-routing.php - About 2 hrs to fix

        Function register_routes has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

                protected function register_routes() {
                    if ( ! empty( $this->singular_query_var ) ) {
                        $slug = $this->get_prefix() . $this->manager->get_singular_slug();
        
                        $pattern = '^' . $this->base;
        Severity: Minor
        Found in src/db-objects/view-routing.php - About 1 hr 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

        Function handle_preview_request has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

                public function handle_preview_request( $query_vars ) {
                    if ( $this->is_preview ) {
                        return true;
                    }
        
        
        Severity: Minor
        Found in src/db-objects/view-routing.php - About 1 hr 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

        Method get_model_sample_permalink_for_property has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                public function get_model_sample_permalink_for_property( $model, $property = '' ) {
                    if ( '' === (string) get_option( 'permalink_structure' ) ) {
                        return '';
                    }
        
        
        Severity: Minor
        Found in src/db-objects/view-routing.php - About 1 hr to fix

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

              abstract class View_Routing extends Service {
                  use Container_Service_Trait, Hooks_Trait;
          
                  /**
                   * The base string to use.
          Severity: Minor
          Found in src/db-objects/view-routing.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

          Function set_document_title has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                  protected function set_document_title( $title ) {
                      if ( ! empty( $title ) ) {
                          return $title;
                      }
          
          
          Severity: Minor
          Found in src/db-objects/view-routing.php - About 1 hr 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

          Method load_template has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  protected function load_template() {
                      global $wp_rewrite;
          
                      $request_method = Fixes::php_filter_input( INPUT_SERVER, 'REQUEST_METHOD' );
          
          
          Severity: Minor
          Found in src/db-objects/view-routing.php - About 1 hr to fix

            Method handle_preview_request has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    public function handle_preview_request( $query_vars ) {
                        if ( $this->is_preview ) {
                            return true;
                        }
            
            
            Severity: Minor
            Found in src/db-objects/view-routing.php - About 1 hr to fix

              Function handle_archive_request has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                      public function handle_archive_request( $query_vars ) {
                          if ( $this->is_archive ) {
                              return true;
                          }
              
              
              Severity: Minor
              Found in src/db-objects/view-routing.php - About 1 hr 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

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

                      protected function get_query_params( $query_vars ) {
                          $number        = $this->per_page;
                          $offset        = ( $this->paged - 1 ) * $number;
                          $no_found_rows = $this->is_singular() ? true : false;
              
              
              Severity: Minor
              Found in src/db-objects/view-routing.php - About 1 hr to fix

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

                        protected function set_document_title( $title ) {
                            if ( ! empty( $title ) ) {
                                return $title;
                            }
                
                
                Severity: Minor
                Found in src/db-objects/view-routing.php - About 1 hr to fix

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

                          protected function register_routes() {
                              if ( ! empty( $this->singular_query_var ) ) {
                                  $slug = $this->get_prefix() . $this->manager->get_singular_slug();
                  
                                  $pattern = '^' . $this->base;
                  Severity: Minor
                  Found in src/db-objects/view-routing.php - About 1 hr to fix

                    Function load_template has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                            protected function load_template() {
                                global $wp_rewrite;
                    
                                $request_method = Fixes::php_filter_input( INPUT_SERVER, 'REQUEST_METHOD' );
                    
                    
                    Severity: Minor
                    Found in src/db-objects/view-routing.php - About 55 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

                    Function handle_singular_request has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                            public function handle_singular_request( $query_vars ) {
                                if ( $this->is_singular ) {
                                    return true;
                                }
                    
                    
                    Severity: Minor
                    Found in src/db-objects/view-routing.php - About 55 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

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

                            public function get_archive_permalink( $page = 1 ) {
                                if ( '' !== (string) get_option( 'permalink_structure' ) ) {
                                    $permalink = $this->base;
                    
                                    if ( $page > 1 ) {
                    Severity: Minor
                    Found in src/db-objects/view-routing.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

                    Avoid too many return statements within this method.
                    Open

                                return true;
                    Severity: Major
                    Found in src/db-objects/view-routing.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return $this->home_url( $permalink, $this->manager->get_prefix() . $this->manager->get_singular_slug() );
                      Severity: Major
                      Found in src/db-objects/view-routing.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return add_query_arg( $this->singular_query_var, $model->$primary_property, $this->home_url() );
                        Severity: Major
                        Found in src/db-objects/view-routing.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return '';
                          Severity: Major
                          Found in src/db-objects/view-routing.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return $this->home_url( $permalink, $this->manager->get_prefix() . $this->manager->get_singular_slug() );
                            Severity: Major
                            Found in src/db-objects/view-routing.php - About 30 mins to fix

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

                                      public function map_matches_to_query_vars( $matches ) {
                                          $query_vars = array();
                              
                                          foreach ( $matches as $key => $value ) {
                                              if ( is_numeric( $key ) ) {
                              Severity: Minor
                              Found in src/db-objects/view-routing.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

                              The method get_model_permalink() has an NPath complexity of 270. The configured NPath complexity threshold is 200.
                              Open

                                      public function get_model_permalink( $model ) {
                                          if ( method_exists( $this->manager, 'get_status_property' ) ) {
                                              $status_property = $this->manager->get_status_property();
                                              if ( ! in_array( $model->$status_property, $this->manager->statuses()->get_public(), true ) ) {
                                                  return '';
                              Severity: Minor
                              Found in src/db-objects/view-routing.php by phpmd

                              NPathComplexity

                              Since: 0.1

                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                              Example

                              class Foo {
                                  function bar() {
                                      // lots of complicated code
                                  }
                              }

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

                              The method get_model_permalink() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
                              Open

                                      public function get_model_permalink( $model ) {
                                          if ( method_exists( $this->manager, 'get_status_property' ) ) {
                                              $status_property = $this->manager->get_status_property();
                                              if ( ! in_array( $model->$status_property, $this->manager->statuses()->get_public(), true ) ) {
                                                  return '';
                              Severity: Minor
                              Found in src/db-objects/view-routing.php by phpmd

                              CyclomaticComplexity

                              Since: 0.1

                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                              Example

                              // Cyclomatic Complexity = 11
                              class Foo {
                              1   public function example() {
                              2       if ($a == $b) {
                              3           if ($a1 == $b1) {
                                              fiddle();
                              4           } elseif ($a2 == $b2) {
                                              fiddle();
                                          } else {
                                              fiddle();
                                          }
                              5       } elseif ($c == $d) {
                              6           while ($c == $d) {
                                              fiddle();
                                          }
                              7        } elseif ($e == $f) {
                              8           for ($n = 0; $n < $h; $n++) {
                                              fiddle();
                                          }
                                      } else {
                                          switch ($z) {
                              9               case 1:
                                                  fiddle();
                                                  break;
                              10              case 2:
                                                  fiddle();
                                                  break;
                              11              case 3:
                                                  fiddle();
                                                  break;
                                              default:
                                                  fiddle();
                                                  break;
                                          }
                                      }
                                  }
                              }

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

                              The method get_model_sample_permalink_for_property() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
                              Open

                                      public function get_model_sample_permalink_for_property( $model, $property = '' ) {
                                          if ( '' === (string) get_option( 'permalink_structure' ) ) {
                                              return '';
                                          }
                              
                              
                              Severity: Minor
                              Found in src/db-objects/view-routing.php by phpmd

                              CyclomaticComplexity

                              Since: 0.1

                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                              Example

                              // Cyclomatic Complexity = 11
                              class Foo {
                              1   public function example() {
                              2       if ($a == $b) {
                              3           if ($a1 == $b1) {
                                              fiddle();
                              4           } elseif ($a2 == $b2) {
                                              fiddle();
                                          } else {
                                              fiddle();
                                          }
                              5       } elseif ($c == $d) {
                              6           while ($c == $d) {
                                              fiddle();
                                          }
                              7        } elseif ($e == $f) {
                              8           for ($n = 0; $n < $h; $n++) {
                                              fiddle();
                                          }
                                      } else {
                                          switch ($z) {
                              9               case 1:
                                                  fiddle();
                                                  break;
                              10              case 2:
                                                  fiddle();
                                                  break;
                              11              case 3:
                                                  fiddle();
                                                  break;
                                              default:
                                                  fiddle();
                                                  break;
                                          }
                                      }
                                  }
                              }

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

                              Avoid using static access to class '\Leaves_And_Love\Plugin_Lib\Fixes' in method 'load_template'.
                              Open

                                          $request_method = Fixes::php_filter_input( INPUT_SERVER, 'REQUEST_METHOD' );
                              Severity: Minor
                              Found in src/db-objects/view-routing.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

                              The method load_template() contains an exit expression.
                              Open

                                          exit;
                              Severity: Minor
                              Found in src/db-objects/view-routing.php by phpmd

                              ExitExpression

                              Since: 0.2

                              An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                              Example

                              class Foo {
                                  public function bar($param)  {
                                      if ($param === 42) {
                                          exit(23);
                                      }
                                  }
                              }

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

                              The method load_template() contains an exit expression.
                              Open

                                              exit;
                              Severity: Minor
                              Found in src/db-objects/view-routing.php by phpmd

                              ExitExpression

                              Since: 0.2

                              An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                              Example

                              class Foo {
                                  public function bar($param)  {
                                      if ($param === 42) {
                                          exit(23);
                                      }
                                  }
                              }

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

                              Avoid excessively long variable names like $singular_template_name. Keep variable name length under 20.
                              Open

                                      protected $singular_template_name = '';
                              Severity: Minor
                              Found in src/db-objects/view-routing.php by phpmd

                              LongVariable

                              Since: 0.2

                              Detects when a field, formal or local variable is declared with a long name.

                              Example

                              class Something {
                                  protected $reallyLongIntName = -3; // VIOLATION - Field
                                  public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                                      $otherReallyLongName = -5; // VIOLATION - Local
                                      for ($interestingIntIndex = 0; // VIOLATION - For
                                           $interestingIntIndex < 10;
                                           $interestingIntIndex++ ) {
                                      }
                                  }
                              }

                              Source https://phpmd.org/rules/naming.html#longvariable

                              Avoid excessively long variable names like $primary_property_value. Keep variable name length under 20.
                              Open

                                              $primary_property_value = absint( $query_vars[ $this->singular_query_var ] );
                              Severity: Minor
                              Found in src/db-objects/view-routing.php by phpmd

                              LongVariable

                              Since: 0.2

                              Detects when a field, formal or local variable is declared with a long name.

                              Example

                              class Something {
                                  protected $reallyLongIntName = -3; // VIOLATION - Field
                                  public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                                      $otherReallyLongName = -5; // VIOLATION - Local
                                      for ($interestingIntIndex = 0; // VIOLATION - For
                                           $interestingIntIndex < 10;
                                           $interestingIntIndex++ ) {
                                      }
                                  }
                              }

                              Source https://phpmd.org/rules/naming.html#longvariable

                              Avoid excessively long variable names like $archive_template_name. Keep variable name length under 20.
                              Open

                                      protected $archive_template_name = '';
                              Severity: Minor
                              Found in src/db-objects/view-routing.php by phpmd

                              LongVariable

                              Since: 0.2

                              Detects when a field, formal or local variable is declared with a long name.

                              Example

                              class Something {
                                  protected $reallyLongIntName = -3; // VIOLATION - Field
                                  public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                                      $otherReallyLongName = -5; // VIOLATION - Local
                                      for ($interestingIntIndex = 0; // VIOLATION - For
                                           $interestingIntIndex < 10;
                                           $interestingIntIndex++ ) {
                                      }
                                  }
                              }

                              Source https://phpmd.org/rules/naming.html#longvariable

                              There are no issues that match your filters.

                              Category
                              Status