felixarntz/wp-site-identity

View on GitHub
src/widgets/class-wp-site-identity-widget.php

Summary

Maintainability
D
2 days
Test Coverage

Function update has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

    public function update( $new_instance, $old_instance ) {
        $instance = $old_instance;

        foreach ( $this->fields as $attr => $field ) {
            switch ( $field['type'] ) {
Severity: Minor
Found in src/widgets/class-wp-site-identity-widget.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

Function form has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    public function form( $instance ) {
        $instance = wp_parse_args( (array) $instance, $this->get_defaults() );

        foreach ( $this->fields as $attr => $field ) {
            $meta = $this->attrs( $field['meta'] );
Severity: Minor
Found in src/widgets/class-wp-site-identity-widget.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

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

class WP_Site_Identity_Widget extends WP_Widget {

    /**
     * Render callback for the widget.
     *

Method form has 79 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function form( $instance ) {
        $instance = wp_parse_args( (array) $instance, $this->get_defaults() );

        foreach ( $this->fields as $attr => $field ) {
            $meta = $this->attrs( $field['meta'] );
Severity: Major
Found in src/widgets/class-wp-site-identity-widget.php - About 3 hrs to fix

    Method update has 54 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function update( $new_instance, $old_instance ) {
            $instance = $old_instance;
    
            foreach ( $this->fields as $attr => $field ) {
                switch ( $field['type'] ) {
    Severity: Major
    Found in src/widgets/class-wp-site-identity-widget.php - About 2 hrs to fix

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

          protected function attrs( $attrs ) {
              $output = '';
      
              foreach ( $attrs as $attr => $value ) {
                  if ( is_bool( $value ) ) {
      Severity: Minor
      Found in src/widgets/class-wp-site-identity-widget.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

      File class-wp-site-identity-widget.php has 252 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      /**
       * WP_Site_Identity_Widget class
       *
       * @package WPSiteIdentity
      Severity: Minor
      Found in src/widgets/class-wp-site-identity-widget.php - About 2 hrs to fix

        Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            public function __construct( $id_base, $name, $description, $render_callback, array $fields = array(), WP_Site_Identity_Widget_Registry $registry = null ) {
        Severity: Minor
        Found in src/widgets/class-wp-site-identity-widget.php - About 45 mins to fix

          The method form() has an NPath complexity of 721. The configured NPath complexity threshold is 200.
          Open

              public function form( $instance ) {
                  $instance = wp_parse_args( (array) $instance, $this->get_defaults() );
          
                  foreach ( $this->fields as $attr => $field ) {
                      $meta = $this->attrs( $field['meta'] );

          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 update() has a Cyclomatic Complexity of 22. The configured cyclomatic complexity threshold is 10.
          Open

              public function update( $new_instance, $old_instance ) {
                  $instance = $old_instance;
          
                  foreach ( $this->fields as $attr => $field ) {
                      switch ( $field['type'] ) {

          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 form() has a Cyclomatic Complexity of 21. The configured cyclomatic complexity threshold is 10.
          Open

              public function form( $instance ) {
                  $instance = wp_parse_args( (array) $instance, $this->get_defaults() );
          
                  foreach ( $this->fields as $attr => $field ) {
                      $meta = $this->attrs( $field['meta'] );

          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 undefined variables such as '$meta' which will lead to PHP notices.
          Open

                              if ( ! empty( $meta['multiple'] ) ) {

          UndefinedVariable

          Since: 2.8.0

          Detects when a variable is used that has not been defined before.

          Example

          class Foo
          {
              private function bar()
              {
                  // $message is undefined
                  echo $message;
              }
          }

          Source https://phpmd.org/rules/cleancode.html#undefinedvariable

          Missing class import via use statement (line '62', column '26').
          Open

                      $this->registry = new WP_Site_Identity_Standard_Widget_Registry();

          MissingImport

          Since: 2.7.0

          Importing all external classes in a file through use statements makes them clearly visible.

          Example

          function make() {
              return new \stdClass();
          }

          Source http://phpmd.org/rules/cleancode.html#MissingImport

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

                              if ( ! empty( $meta['multiple'] ) ) {

          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

          Expected 1 space before closing PHP tag; 0 found
          Open

                                  <select id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" class="widefat"<?php echo $meta; // WPCS: XSS OK. ?>>

          Expected 1 space before closing PHP tag; 0 found
          Open

                                  <textarea id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" class="widefat"<?php echo $meta; // WPCS: XSS OK. ?>><?php echo esc_textarea( $instance[ $attr ] ); ?></textarea>

          Expected 1 space before closing PHP tag; 0 found
          Open

                                  <input type="checkbox" id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" class="widefat" value="1"<?php checked( $instance[ $attr ] ); ?><?php echo $meta; // WPCS: XSS OK. ?> />

          Expected 1 space before closing PHP tag; 0 found
          Open

                                  <input type="number" id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" class="tiny-text" value="<?php echo esc_attr( $instance[ $attr ] ); ?>"<?php echo $meta; // WPCS: XSS OK. ?> />

          Expected 1 space before closing PHP tag; 0 found
          Open

                                  <input type="<?php echo esc_attr( $field['type'] ); ?>" id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" class="widefat" value="<?php echo esc_attr( $instance[ $attr ] ); ?>"<?php echo $meta; // WPCS: XSS OK. ?> />

          Expected 1 space before closing PHP tag; 0 found
          Open

                                      <input type="radio" id="<?php echo esc_attr( $id . '-' . $value ); ?>" name="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $value ); ?>"<?php checked( $instance[ $attr ], $value ); ?><?php echo $meta; // WPCS: XSS OK. ?> />

          Line indented incorrectly; expected 6 tabs, found 5
          Open

                              case 'email':

          Line indented incorrectly; expected 8 tabs, found 5
          Open

                              case 'date':

          Line indented incorrectly; expected 7 tabs, found 5
          Open

                              case 'url':

          Line indented incorrectly; expected 10 tabs, found 5
          Open

                              default:

          Line indented incorrectly; expected 9 tabs, found 5
          Open

                              case 'text':

          There are no issues that match your filters.

          Category
          Status