felixarntz/plugin-lib

View on GitHub
src/db-objects/models-list-page.php

Summary

Maintainability
C
1 day
Test Coverage

Function bulk_action_delete has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

        protected function bulk_action_delete( $ids ) {
            $errors = new WP_Error();

            $capabilities   = $this->model_manager->capabilities();
            $title_property = method_exists( $this->model_manager, 'get_title_property' ) ? $this->model_manager->get_title_property() : '';
Severity: Minor
Found in src/db-objects/models-list-page.php - About 3 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

Function render_form has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

        protected function render_form() {
            $this->list_table->views();

            ?>
            <form id="<?php echo esc_attr( $this->model_manager->get_plural_slug() . '-filter' ); ?>" method="get">
Severity: Minor
Found in src/db-objects/models-list-page.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 bulk_action_delete has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        protected function bulk_action_delete( $ids ) {
            $errors = new WP_Error();

            $capabilities   = $this->model_manager->capabilities();
            $title_property = method_exists( $this->model_manager, 'get_title_property' ) ? $this->model_manager->get_title_property() : '';
Severity: Minor
Found in src/db-objects/models-list-page.php - About 1 hr to fix

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

            protected function render_form() {
                $this->list_table->views();
    
                ?>
                <form id="<?php echo esc_attr( $this->model_manager->get_plural_slug() . '-filter' ); ?>" method="get">
    Severity: Minor
    Found in src/db-objects/models-list-page.php - About 1 hr to fix

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

              public function __construct( $slug, $manager, $model_manager ) {
                  parent::__construct( $slug, $manager, $model_manager );
      
                  if ( empty( $this->title ) ) {
                      $this->title = $this->model_manager->get_message( 'list_page_items' );
      Severity: Minor
      Found in src/db-objects/models-list-page.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_actions has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

              protected function handle_actions() {
                  $doaction = $this->list_table->current_action();
      
                  if ( ! $doaction ) {
                      return;
      Severity: Minor
      Found in src/db-objects/models-list-page.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 handle_actions has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              protected function handle_actions() {
                  $doaction = $this->list_table->current_action();
      
                  if ( ! $doaction ) {
                      return;
      Severity: Minor
      Found in src/db-objects/models-list-page.php - About 1 hr to fix

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

                protected function render_header() {
                    $capabilities = $this->model_manager->capabilities();
        
                    $new_page_url = '';
                    if ( ! empty( $this->edit_page_slug ) ) {
        Severity: Minor
        Found in src/db-objects/models-list-page.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

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

                protected function bulk_action_delete( $ids ) {
                    $errors = new WP_Error();
        
                    $capabilities   = $this->model_manager->capabilities();
                    $title_property = method_exists( $this->model_manager, 'get_title_property' ) ? $this->model_manager->get_title_property() : '';
        Severity: Minor
        Found in src/db-objects/models-list-page.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 handle_actions() contains an exit expression.
        Open

                    exit;
        Severity: Minor
        Found in src/db-objects/models-list-page.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 handle_actions() contains an exit expression.
        Open

                        exit;
        Severity: Minor
        Found in src/db-objects/models-list-page.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 using static access to class '\Leaves_And_Love\Plugin_Lib\Assets' in method 'enqueue_assets'.
        Open

                    $assets = Assets::get_library_instance();
        Severity: Minor
        Found in src/db-objects/models-list-page.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 excessively long variable names like $list_table_class_name. Keep variable name length under 20.
        Open

                protected $list_table_class_name = Models_List_Table::class;
        Severity: Minor
        Found in src/db-objects/models-list-page.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