felixarntz/wpdlib

View on GitHub
inc/WPDLib/Components/Base.php

Summary

Maintainability
D
1 day
Test Coverage

Function is_valid_slug has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

        public function is_valid_slug( $parent = null ) {
            if ( $this->valid_slug === null ) {
                $globalnames = $this->supports_globalslug();
                if ( $globalnames !== true ) {
                    if ( $globalnames !== false ) {
Severity: Minor
Found in inc/WPDLib/Components/Base.php - About 5 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 validate has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

        public function validate( $parent = null ) {
            if ( null !== $parent ) {
                if ( count( $this->parents ) > 0 && ! $this->supports_multiparents() ) {
                    return new UtilError( 'no_multiparent_component', sprintf( __( 'The component %1$s of class %2$s already has a parent assigned and is not a multiparent component.', 'wpdlib' ), $this->slug, get_class( $this ) ), '', ComponentManager::get_scope() );
                }
Severity: Minor
Found in inc/WPDLib/Components/Base.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

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

        public function add( $component ) {
            if ( ComponentManager::is_too_late() ) {
                return new UtilError( 'too_late_component', sprintf( __( 'Components must not be added later than the %s hook.', 'wpdlib' ), '<code>init</code>' ), '', ComponentManager::get_scope() );
            }

Severity: Minor
Found in inc/WPDLib/Components/Base.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 is_valid_slug has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        public function is_valid_slug( $parent = null ) {
            if ( $this->valid_slug === null ) {
                $globalnames = $this->supports_globalslug();
                if ( $globalnames !== true ) {
                    if ( $globalnames !== false ) {
Severity: Minor
Found in inc/WPDLib/Components/Base.php - About 1 hr to fix

    Avoid deeply nested control flow statements.
    Open

                                    if ( $parent === null ) {
                                        $found = false;
                                        break;
                                    }
    Severity: Major
    Found in inc/WPDLib/Components/Base.php - About 45 mins to fix

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

              public function get_children( $class = '' ) {
                  $children = array();
      
                  if ( $class && '*' !== $class ) {
                      if ( isset( $this->children[ $class ] ) ) {
      Severity: Minor
      Found in inc/WPDLib/Components/Base.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 $component;
      Severity: Major
      Found in inc/WPDLib/Components/Base.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                        return new UtilError( 'no_valid_slug_component', sprintf( __( 'A component of class %1$s with slug %2$s already exists.', 'wpdlib' ), get_class( $component ), $component->slug ), '', ComponentManager::get_scope() );
        Severity: Major
        Found in inc/WPDLib/Components/Base.php - About 30 mins to fix

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

                  public function get_parent( $index = 0, $depth = 1 ) {
                      $current = $this;
                      for ( $i = 0; $i < $depth; $i++ ) {
                          $parents = array_values( $current->parents );
                          if ( isset( $parents[ $index ] ) ) {
          Severity: Minor
          Found in inc/WPDLib/Components/Base.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

          There are no issues that match your filters.

          Category
          Status