WP-API/WP-API

View on GitHub

Showing 222 of 244 total issues

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

    public function update_item( $request ) {
        $id = (int) $request['id'];
        $post = $this->get_post( $id );

        if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
Severity: Major
Found in lib/endpoints/class-wp-rest-posts-controller.php - About 2 hrs to fix

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

    <?php
    
    class WP_REST_Revisions_Controller extends WP_REST_Controller {
    
        private $parent_post_type;
    Severity: Minor
    Found in lib/endpoints/class-wp-rest-revisions-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

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

          public static function get_filename_from_disposition( $disposition_header ) {
              // Get the filename.
              $filename = null;
      
              foreach ( $disposition_header as $value ) {
      Severity: Minor
      Found in lib/endpoints/class-wp-rest-attachments-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

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

          protected function get_registered_fields() {
              $registered = array();
      
              foreach ( get_registered_meta_keys( $this->get_meta_type() ) as $name => $args ) {
                  if ( empty( $args['show_in_rest'] ) ) {
      Severity: Minor
      Found in lib/fields/class-wp-rest-meta-fields.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 get_item_schema has 50 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'                => 'status',
                    'type'                 => 'object',
        Severity: Minor
        Found in lib/endpoints/class-wp-rest-post-statuses-controller.php - About 2 hrs to fix

          Function create_item_permissions_check has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              public function create_item_permissions_check( $request ) {
          
                  if ( ! is_user_logged_in() && get_option( 'comment_registration' ) ) {
                      return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) );
                  }
          Severity: Minor
          Found in lib/endpoints/class-wp-rest-comments-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 update_item has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function update_item( $request ) {
                  $id = (int) $request['id'];
          
                  $comment = get_comment( $id );
                  if ( empty( $comment ) ) {
          Severity: Minor
          Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr 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

              Method register_routes has 46 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: Minor
              Found in lib/endpoints/class-wp-rest-posts-controller.php - About 1 hr to fix

                Method upload_from_data has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function upload_from_data( $data, $headers ) {
                        if ( empty( $data ) ) {
                            return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) );
                        }
                
                
                Severity: Minor
                Found in lib/endpoints/class-wp-rest-attachments-controller.php - About 1 hr to fix

                  Method get_item_schema has 44 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'                => 'type',
                              'type'                 => 'object',
                  Severity: Minor
                  Found in lib/endpoints/class-wp-rest-post-types-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_response has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function prepare_item_for_response( $post, $request ) {
                            $response = parent::prepare_item_for_response( $post, $request );
                            $data = $response->get_data();
                    
                            $data['alt_text']      = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
                    Severity: Minor
                    Found in lib/endpoints/class-wp-rest-attachments-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 update_multi_meta_value has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected function update_multi_meta_value( $object_id, $name, $values ) {
                            if ( ! current_user_can( 'edit_post_meta', $object_id, $name ) ) {
                                return new WP_Error(
                                    'rest_cannot_update',
                                    sprintf( __( 'You do not have permission to edit the %s custom field.' ), $name ),
                    Severity: Minor
                    Found in lib/fields/class-wp-rest-meta-fields.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 register_routes has 43 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: Minor
                    Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

                      Function sync has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                                  sync: function( method, model, options ) {
                                      var beforeSend, success,
                                          self = this;
                      
                                      options    = options || {};
                      Severity: Minor
                      Found in wp-api.js - About 1 hr to fix

                        Method register_routes has 43 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: Minor
                        Found in lib/endpoints/class-wp-rest-terms-controller.php - About 1 hr to fix

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

                              public function prepare_item_for_response( $post, $request ) {
                                  $response = parent::prepare_item_for_response( $post, $request );
                                  $data = $response->get_data();
                          
                                  $data['alt_text']      = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
                          Severity: Minor
                          Found in lib/endpoints/class-wp-rest-attachments-controller.php - About 1 hr to fix
                            Severity
                            Category
                            Status
                            Source
                            Language