felixarntz/global-admin

View on GitHub
wp-global-admin/wp-admin/includes/class-wp-ga-users-list-table.php

Summary

Maintainability
B
5 hrs
Test Coverage

Method prepare_items has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function prepare_items() {
        global $usersearch, $role, $wpdb, $mode;

        $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';

Severity: Major
Found in wp-global-admin/wp-admin/includes/class-wp-ga-users-list-table.php - About 2 hrs to fix

    Function prepare_items has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        public function prepare_items() {
            global $usersearch, $role, $wpdb, $mode;
    
            $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
    
    
    Severity: Minor
    Found in wp-global-admin/wp-admin/includes/class-wp-ga-users-list-table.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 column_networks has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function column_networks( $user ) {
            if ( ! function_exists( 'get_networks_of_user' ) ) {
                return;
            }
    
    
    Severity: Minor
    Found in wp-global-admin/wp-admin/includes/class-wp-ga-users-list-table.php - About 1 hr to fix

      Function column_networks has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          public function column_networks( $user ) {
              if ( ! function_exists( 'get_networks_of_user' ) ) {
                  return;
              }
      
      
      Severity: Minor
      Found in wp-global-admin/wp-admin/includes/class-wp-ga-users-list-table.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

      The method prepare_items() has an NPath complexity of 1728. The configured NPath complexity threshold is 200.
      Open

          public function prepare_items() {
              global $usersearch, $role, $wpdb, $mode;
      
              $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
      
      

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

          public function prepare_items() {
              global $usersearch, $role, $wpdb, $mode;
      
              $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
      
      

      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

      Missing class import via use statement (line '109', column '25').
      Open

              $wp_user_search = new WP_User_Query( $args );

      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 '$edit'.
      Open

                  $edit      = "<a href=\"{$edit_link}\">{$user->user_login}</a>";

      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

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

              global $usersearch, $role, $wpdb, $mode;

      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

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

              $global_administrators = get_global_administrators();

      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 variables with short names like $i. Configured minimum length is 3.
      Open

                  $i            = 0;

      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

      Overriding WordPress globals is prohibited. Found assignment to $role
      Open

              $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '"<span class="$action">$link$sep</span>"'.
      Open

                      echo "<span class='$action'>$link$sep</span>";

      Missing wp_unslash() before sanitization.
      Open

                  $args['order'] = $_REQUEST['order'];

      Missing wp_unslash() before sanitization.
      Open

                  $args['orderby'] = $_REQUEST['orderby'];

      Detected usage of a non-sanitized input variable: $_REQUEST
      Open

              $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';

      Overriding WordPress globals is prohibited. Found assignment to $usersearch
      Open

              $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';

      A gettext call containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.
      Open

              $role_links['global'] = "<a href='" . global_admin_url( 'users.php?role=global' ) . "'$class>" . sprintf( _n( 'Global Administrator <span class="count">(%s)</span>', 'Global Administrators <span class="count">(%s)</span>', $total_admins, 'wp-global-admin' ), number_format_i18n( $total_admins ) ) . '</a>';

      A gettext call containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.
      Open

              $role_links['all'] = "<a href='" . global_admin_url( 'users.php' ) . "'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users', 'wp-global-admin' ), number_format_i18n( $total_users ) ) . '</a>';

      Detected usage of a non-validated input variable: $_SERVER
      Open

                  $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$this'.
      Open

              echo $this->column_networks( $user );

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$network'.
      Open

                  echo '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $network->id ) ) . '">' . $network->domain . $path . '</a>';

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$data'.
      Open

              echo '<td class="', $classes, ' has-row-actions" ', $data, '>';

      Detected usage of a non-sanitized input variable: $_REQUEST
      Open

                  $args['order'] = $_REQUEST['order'];

      Detected usage of a non-validated input variable: $_SERVER
      Open

                  $delete_link       = esc_url( global_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) );

      Overriding WordPress globals is prohibited. Found assignment to $mode
      Open

                  $mode = get_user_setting( 'global_users_list_mode', 'list' );

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$avatar'.
      Open

              echo $avatar;

      Overriding WordPress globals is prohibited. Found assignment to $mode
      Open

                  $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$primary'.
      Open

              echo $this->handle_row_actions( $user, 'networks', $primary );

      Detected usage of a non-sanitized input variable: $_SERVER
      Open

                  $delete_link       = esc_url( global_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) );

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$user'.
      Open

                  <a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a>

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$path'.
      Open

                  echo '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $network->id ) ) . '">' . $network->domain . $path . '</a>';

      Detected usage of a non-sanitized input variable: $_REQUEST
      Open

              $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';

      Missing wp_unslash() before sanitization.
      Open

              $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$classes'.
      Open

              echo '<td class="', $classes, ' has-row-actions" ', $data, '>';

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$this'.
      Open

              echo $this->handle_row_actions( $user, 'networks', $primary );

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'.
      Open

                      echo ' - ' . __( 'Global Administrator' );

      Detected usage of a non-validated input variable: $_SERVER
      Open

                  $edit_link       = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );

      Missing wp_unslash() before sanitization.
      Open

              $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';

      Detected usage of a non-sanitized input variable: $_REQUEST
      Open

                  $args['orderby'] = $_REQUEST['orderby'];

      Detected usage of a non-sanitized input variable: $_SERVER
      Open

                  $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$edit_link'.
      Open

                  <a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a>

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$network'.
      Open

                  echo '<span class="network-' . $network->id . '" >';

      Detected usage of a non-sanitized input variable: $_SERVER
      Open

                  $edit_link       = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );

      There are no issues that match your filters.

      Category
      Status