WP-API/WP-API

View on GitHub
lib/endpoints/class-wp-rest-users-controller.php

Summary

Maintainability
F
6 days
Test Coverage

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

<?php

/**
 * Access users
 */
Severity: Major
Found in lib/endpoints/class-wp-rest-users-controller.php - About 1 day to fix

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

        public function get_item_schema() {
            $schema = array(
                '$schema'    => 'http://json-schema.org/draft-04/schema#',
                'title'      => 'user',
                'type'       => 'object',
    Severity: Major
    Found in lib/endpoints/class-wp-rest-users-controller.php - About 5 hrs to fix

      Method get_items has 77 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function get_items( $request ) {
      
              // Retrieve the list of registered collection query parameters.
              $registered = $this->get_collection_params();
      
      
      Severity: Major
      Found in lib/endpoints/class-wp-rest-users-controller.php - About 3 hrs to fix

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

            public function create_item( $request ) {
                if ( ! empty( $request['id'] ) ) {
                    return new WP_Error( 'rest_user_exists', __( 'Cannot create existing resource.' ), array( 'status' => 400 ) );
                }
        
        
        Severity: Minor
        Found in lib/endpoints/class-wp-rest-users-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 prepare_item_for_response has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function prepare_item_for_response( $user, $request ) {
        
                $data = array();
                $schema = $this->get_item_schema();
                if ( ! empty( $schema['properties']['id'] ) ) {
        Severity: Major
        Found in lib/endpoints/class-wp-rest-users-controller.php - About 2 hrs to fix

          Function prepare_item_for_response has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              public function prepare_item_for_response( $user, $request ) {
          
                  $data = array();
                  $schema = $this->get_item_schema();
                  if ( ! empty( $schema['properties']['id'] ) ) {
          Severity: Minor
          Found in lib/endpoints/class-wp-rest-users-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 get_collection_params has 55 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function get_collection_params() {
                  $query_params = parent::get_collection_params();
          
                  $query_params['context']['default'] = 'view';
          
          
          Severity: Major
          Found in lib/endpoints/class-wp-rest-users-controller.php - About 2 hrs to fix

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

                public function create_item( $request ) {
                    if ( ! empty( $request['id'] ) ) {
                        return new WP_Error( 'rest_user_exists', __( 'Cannot create existing resource.' ), array( 'status' => 400 ) );
                    }
            
            
            Severity: Major
            Found in lib/endpoints/class-wp-rest-users-controller.php - About 2 hrs to fix

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

                  public function get_items( $request ) {
              
                      // Retrieve the list of registered collection query parameters.
                      $registered = $this->get_collection_params();
              
              
              Severity: Minor
              Found in lib/endpoints/class-wp-rest-users-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 52 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function register_routes() {
              
                      register_rest_route( $this->namespace, '/' . $this->rest_base, array(
                          array(
                              'methods'         => WP_REST_Server::READABLE,
              Severity: Major
              Found in lib/endpoints/class-wp-rest-users-controller.php - About 2 hrs to fix

                Method update_item has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function update_item( $request ) {
                        $id = (int) $request['id'];
                
                        $user = get_userdata( $id );
                        if ( ! $user ) {
                Severity: Minor
                Found in lib/endpoints/class-wp-rest-users-controller.php - About 1 hr to fix

                  Function update_item has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function update_item( $request ) {
                          $id = (int) $request['id'];
                  
                          $user = get_userdata( $id );
                          if ( ! $user ) {
                  Severity: Minor
                  Found in lib/endpoints/class-wp-rest-users-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

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

                      protected function prepare_item_for_database( $request ) {
                          $prepared_user = new stdClass;
                  
                          $schema = $this->get_item_schema();
                  
                  
                  Severity: Minor
                  Found in lib/endpoints/class-wp-rest-users-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 prepare_item_for_database has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function prepare_item_for_database( $request ) {
                          $prepared_user = new stdClass;
                  
                          $schema = $this->get_item_schema();
                  
                  
                  Severity: Minor
                  Found in lib/endpoints/class-wp-rest-users-controller.php - About 1 hr to fix

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

                        protected function check_role_update( $user_id, $roles ) {
                            global $wp_roles;
                    
                            foreach ( $roles as $role ) {
                    
                    
                    Severity: Minor
                    Found in lib/endpoints/class-wp-rest-users-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 delete_item has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function delete_item( $request ) {
                            $id = (int) $request['id'];
                            $reassign = isset( $request['reassign'] ) ? absint( $request['reassign'] ) : null;
                            $force = isset( $request['force'] ) ? (bool) $request['force'] : false;
                    
                    
                    Severity: Minor
                    Found in lib/endpoints/class-wp-rest-users-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 $response;
                    Severity: Major
                    Found in lib/endpoints/class-wp-rest-users-controller.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return $fields_update;
                      Severity: Major
                      Found in lib/endpoints/class-wp-rest-users-controller.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

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

                          Avoid too many return statements within this method.
                          Open

                                      return $fields_update;
                          Severity: Major
                          Found in lib/endpoints/class-wp-rest-users-controller.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return $check_permission;
                            Severity: Major
                            Found in lib/endpoints/class-wp-rest-users-controller.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return $meta_update;
                              Severity: Major
                              Found in lib/endpoints/class-wp-rest-users-controller.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return $meta_update;
                                Severity: Major
                                Found in lib/endpoints/class-wp-rest-users-controller.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

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

                                    Avoid too many return statements within this method.
                                    Open

                                                return $user_id;
                                    Severity: Major
                                    Found in lib/endpoints/class-wp-rest-users-controller.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                      return $user_id;
                                      Severity: Major
                                      Found in lib/endpoints/class-wp-rest-users-controller.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                        return $user_id;
                                        Severity: Major
                                        Found in lib/endpoints/class-wp-rest-users-controller.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

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

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

                                                public function get_item_permissions_check( $request ) {
                                            
                                                    $id = (int) $request['id'];
                                                    $user = get_userdata( $id );
                                                    $types = get_post_types( array( 'show_in_rest' => true ), 'names' );
                                            Severity: Minor
                                            Found in lib/endpoints/class-wp-rest-users-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

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                    if ( get_option( 'show_avatars' ) ) {
                                                        $avatar_properties = array();
                                            
                                                        $avatar_sizes = rest_get_avatar_sizes();
                                                        foreach ( $avatar_sizes as $size ) {
                                            Severity: Major
                                            Found in lib/endpoints/class-wp-rest-users-controller.php and 1 other location - About 3 hrs to fix
                                            lib/endpoints/class-wp-rest-comments-controller.php on lines 1057..1077

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 157.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            There are no issues that match your filters.

                                            Category
                                            Status