WP-API/WP-API

View on GitHub

Showing 244 of 244 total issues

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

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

    public function create_item( $request ) {
        if ( isset( $request['parent'] ) ) {
            if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
                return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
            }
Severity: Minor
Found in lib/endpoints/class-wp-rest-terms-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 13 (exceeds 5 allowed). Consider refactoring.
Open

    public function prepare_item_for_response( $post, $request ) {

        $schema = $this->get_item_schema();

        $data = array();
Severity: Minor
Found in lib/endpoints/class-wp-rest-revisions-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_item has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    public function update_item( $request ) {
        if ( isset( $request['parent'] ) ) {
            if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
                return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
            }
Severity: Minor
Found in lib/endpoints/class-wp-rest-terms-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

    Method get_registered_fields has 38 lines of code (exceeds 25 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 1 hr to fix

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

          public function create_item( $request ) {
              if ( isset( $request['parent'] ) ) {
                  if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
                      return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
                  }
      Severity: Minor
      Found in lib/endpoints/class-wp-rest-terms-controller.php - About 1 hr to fix

        Function get_registered_options has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function get_registered_options() {
                $rest_options = array();
        
                foreach ( get_registered_settings() as $name => $args ) {
                    if ( empty( $args['show_in_rest'] ) ) {
        Severity: Minor
        Found in lib/endpoints/class-wp-rest-settings-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 delete_item has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            public function delete_item( $request ) {
                $id = (int) $request['id'];
                $force = (bool) $request['force'];
        
                $post = $this->get_post( $id );
        Severity: Minor
        Found in lib/endpoints/class-wp-rest-posts-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 initialize has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                initialize: function() {
                    var model = this, deferred;
        
                    Backbone.Model.prototype.initialize.apply( model, arguments );
        
        
        Severity: Minor
        Found in wp-api.js - About 1 hr to fix

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

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

            Method get_items_permissions_check has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function get_items_permissions_check( $request ) {
            
                    if ( ! empty( $request['post'] ) ) {
                        foreach ( (array) $request['post'] as $post_id ) {
                            $post = $this->get_post( $post_id );
            Severity: Minor
            Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

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

                  public function prepare_item_for_response( $comment, $request ) {
                      $data = array(
                          'id'                 => (int) $comment->comment_ID,
                          'post'               => (int) $comment->comment_post_ID,
                          'parent'             => (int) $comment->comment_parent,
              Severity: Minor
              Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

                Method get_endpoint_args_for_item_schema has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
                
                        $schema                = $this->get_item_schema();
                        $schema_properties     = ! empty( $schema['properties'] ) ? $schema['properties'] : array();
                        $endpoint_args = array();
                Severity: Minor
                Found in lib/endpoints/class-wp-rest-controller.php - About 1 hr to fix

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

                      public function update_item( $request ) {
                          if ( isset( $request['parent'] ) ) {
                              if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
                                  return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
                              }
                  Severity: Minor
                  Found in lib/endpoints/class-wp-rest-terms-controller.php - About 1 hr to fix

                    Method delete_item has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function delete_item( $request ) {
                            $id = (int) $request['id'];
                            $force = (bool) $request['force'];
                    
                            $post = $this->get_post( $id );
                    Severity: Minor
                    Found in lib/endpoints/class-wp-rest-posts-controller.php - About 1 hr to fix

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

                          public function get_value( $object_id, $request ) {
                              $fields   = $this->get_registered_fields();
                              $response = array();
                      
                              foreach ( $fields as $name => $args ) {
                      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 handle_status_param has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          protected function handle_status_param( $new_status, $comment ) {
                              $old_status = wp_get_comment_status( $comment->comment_ID );
                      
                              if ( $new_status === $old_status ) {
                                  return false;
                      Severity: Minor
                      Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

                        Method create_item_permissions_check has 30 lines of code (exceeds 25 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

                          Function buildCollectionGetter has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                                      buildCollectionGetter = function( parentModel, collectionName, embedSourcePoint, embedIndex ) {
                                          /**
                                           * Returns a promise that resolves to the requested collection
                                           *
                                           * Uses the embedded data if available, otherwises fetches the
                          Severity: Minor
                          Found in wp-api.js - About 1 hr to fix
                            Severity
                            Category
                            Status
                            Source
                            Language