WordPress/WordPress

View on GitHub
wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php

Summary

Maintainability
F
4 days
Test Coverage

File class-wp-rest-plugins-controller.php has 618 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * REST API: WP_REST_Plugins_Controller class
 *
 * @package WordPress
Severity: Major
Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 1 day to fix

    Method create_item has 103 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function create_item( $request ) {
            global $wp_filesystem;
    
            require_once ABSPATH . 'wp-admin/includes/file.php';
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
    Severity: Major
    Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 4 hrs to fix

      Method get_item_schema has 96 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function get_item_schema() {
              if ( $this->schema ) {
                  return $this->add_additional_fields_schema( $this->schema );
              }
      
      
      Severity: Major
      Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 3 hrs to fix

        WP_REST_Plugins_Controller has 26 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class WP_REST_Plugins_Controller extends WP_REST_Controller {
        
            const PATTERN = '[^.\/]+(?:\/[^.\/]+)?';
        
            /**
        Severity: Minor
        Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 3 hrs to fix

          Function create_item has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

              public function create_item( $request ) {
                  global $wp_filesystem;
          
                  require_once ABSPATH . 'wp-admin/includes/file.php';
                  require_once ABSPATH . 'wp-admin/includes/plugin.php';
          Severity: Minor
          Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.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 register_routes has 64 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function register_routes() {
                  register_rest_route(
                      $this->namespace,
                      '/' . $this->rest_base,
                      array(
          Severity: Major
          Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 2 hrs to fix

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

                protected function does_plugin_match_request( $request, $item ) {
                    $search = $request['search'];
            
                    if ( $search ) {
                        $matched_search = false;
            Severity: Minor
            Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.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 delete_item has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function delete_item( $request ) {
                    require_once ABSPATH . 'wp-admin/includes/file.php';
                    require_once ABSPATH . 'wp-admin/includes/plugin.php';
            
                    $data = $this->get_plugin_data( $request['plugin'] );
            Severity: Minor
            Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 1 hr to fix

              Method prepare_item_for_response has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function prepare_item_for_response( $item, $request ) {
                      $fields = $this->get_fields_for_response( $request );
              
                      $item   = _get_plugin_data_markup_translate( $item['_file'], $item, false );
                      $marked = _get_plugin_data_markup_translate( $item['_file'], $item, true );
              Severity: Minor
              Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 1 hr to fix

                Function plugin_status_permission_check has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function plugin_status_permission_check( $plugin, $new_status, $current_status ) {
                        if ( is_multisite() && ( 'network-active' === $current_status || 'network-active' === $new_status ) && ! current_user_can( 'manage_network_plugins' ) ) {
                            return new WP_Error(
                                'rest_cannot_manage_network_plugins',
                                __( 'Sorry, you are not allowed to manage network plugins.' ),
                Severity: Minor
                Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 45 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_items has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function get_items( $request ) {
                        require_once ABSPATH . 'wp-admin/includes/plugin.php';
                
                        $plugins = array();
                
                
                Severity: Minor
                Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.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 in_array( $pack->language, $installed_locales, true );
                Severity: Major
                Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                  return $can_change_status;
                  Severity: Major
                  Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return $response;
                    Severity: Major
                    Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return new WP_REST_Response(
                                  array(
                                      'deleted'  => true,
                                      'previous' => $prepared->get_data(),
                                  )
                      Severity: Major
                      Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return $error;
                        Severity: Major
                        Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return new WP_Error(
                                              'unable_to_connect_to_filesystem',
                                              $wp_filesystem->errors->get_error_message(),
                                              array( 'status' => 500 )
                                          );
                          Severity: Major
                          Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return (object) $item;
                            Severity: Major
                            Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                          return new WP_Error(
                                              'unable_to_connect_to_filesystem',
                                              __( 'Unable to connect to the filesystem. Please confirm your credentials.' ),
                                              array( 'status' => 500 )
                                          );
                              Severity: Major
                              Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return true;
                                Severity: Major
                                Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                              return new WP_Error(
                                                  'unable_to_determine_installed_plugin',
                                                  __( 'Unable to determine what plugin was installed.' ),
                                                  array( 'status' => 500 )
                                              );
                                  Severity: Major
                                  Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    return $changed_status;
                                    Severity: Major
                                    Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php - About 30 mins to fix

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

                                          public function update_item_permissions_check( $request ) {
                                              require_once ABSPATH . 'wp-admin/includes/plugin.php';
                                      
                                              if ( ! current_user_can( 'activate_plugins' ) ) {
                                                  return new WP_Error(
                                      Severity: Minor
                                      Found in wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.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