WP-API/WP-API

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

Summary

Maintainability
D
3 days
Test Coverage

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

<?php

class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {

    /**
Severity: Minor
Found in lib/endpoints/class-wp-rest-attachments-controller.php - About 5 hrs to fix

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

        public function create_item( $request ) {
    
            if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) {
                return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) );
            }
    Severity: Major
    Found in lib/endpoints/class-wp-rest-attachments-controller.php - About 2 hrs to fix

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

          public function get_item_schema() {
      
              $schema = parent::get_item_schema();
      
              $schema['properties']['alt_text'] = array(
      Severity: Major
      Found in lib/endpoints/class-wp-rest-attachments-controller.php - About 2 hrs to fix

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

            public function create_item( $request ) {
        
                if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) {
                    return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) );
                }
        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_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

        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

          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

          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

            Function upload_from_data has a Cognitive Complexity of 9 (exceeds 5 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 55 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 upload_from_file has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function upload_from_file( $files, $headers ) {
                    if ( empty( $files ) ) {
                        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 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

            Function prepare_items_query has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function prepare_items_query( $prepared_args = array(), $request = null ) {
                    $query_args = parent::prepare_items_query( $prepared_args, $request );
                    if ( empty( $query_args['post_status'] ) || ! in_array( $query_args['post_status'], array( 'inherit', 'private', 'trash' ), true ) ) {
                        $query_args['post_status'] = 'inherit';
                    }
            Severity: Minor
            Found in lib/endpoints/class-wp-rest-attachments-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 new WP_Error( 'rest_upload_sideload_error', $sideloaded['error'], array( 'status' => 500 ) );
            Severity: Major
            Found in lib/endpoints/class-wp-rest-attachments-controller.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

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

                Avoid too many return statements within this method.
                Open

                                return new WP_Error( 'rest_upload_hash_mismatch', __( 'Content hash did not match expected.' ), array( 'status' => 412 ) );
                Severity: Major
                Found in lib/endpoints/class-wp-rest-attachments-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-attachments-controller.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return new WP_Error( 'rest_upload_file_error', __( 'Could not open file handle.' ), array( 'status' => 500 ) );
                    Severity: Major
                    Found in lib/endpoints/class-wp-rest-attachments-controller.php - About 30 mins to fix

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

                          public function create_item_permissions_check( $request ) {
                              $ret = parent::create_item_permissions_check( $request );
                              if ( ! $ret || is_wp_error( $ret ) ) {
                                  return $ret;
                              }
                      Severity: Minor
                      Found in lib/endpoints/class-wp-rest-attachments-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