WP-API/WP-API

View on GitHub

Showing 244 of 244 total issues

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

<?php

class WP_REST_Posts_Controller extends WP_REST_Controller {

    /**
Severity: Major
Found in lib/endpoints/class-wp-rest-posts-controller.php - About 3 days to fix

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

                CategoriesMixin = {
    
                    /**
                     * Get a the categories for a post.
                     *
    Severity: Major
    Found in wp-api.js and 1 other location - About 2 days to fix
    wp-api.js on lines 445..524

    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 433.

    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

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

                TagsMixin = {
    
                    /**
                     * Get the tags for a post.
                     *
    Severity: Major
    Found in wp-api.js and 1 other location - About 2 days to fix
    wp-api.js on lines 529..609

    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 433.

    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

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

    <?php
    
    /**
     * Access comments
     */
    Severity: Major
    Found in lib/endpoints/class-wp-rest-comments-controller.php - About 2 days to fix

      Function rest_validate_request_arg has a Cognitive Complexity of 83 (exceeds 5 allowed). Consider refactoring.
      Open

          function rest_validate_request_arg( $value, $request, $param ) {
      
              $attributes = $request->get_attributes();
              if ( ! isset( $attributes['args'][ $param ] ) || ! is_array( $attributes['args'][ $param ] ) ) {
                  return true;
      Severity: Minor
      Found in plugin.php - About 1 day 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

          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-terms-controller.php and 1 other location - About 1 day to fix
      lib/endpoints/class-wp-rest-comments-controller.php on lines 26..72

      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 353.

      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

      Similar blocks of code found in 2 locations. 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-comments-controller.php and 1 other location - About 1 day to fix
      lib/endpoints/class-wp-rest-terms-controller.php on lines 57..102

      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 353.

      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

      File wp-api.js has 710 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      (function( window, undefined ) {
      
          'use strict';
      
          /**
      Severity: Major
      Found in wp-api.js - About 1 day to fix

        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 299 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'      => $this->post_type,
          Severity: Major
          Found in lib/endpoints/class-wp-rest-posts-controller.php - About 1 day to fix

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

            <?php
            
            /**
             * Access terms associated with a taxonomy.
             */
            Severity: Major
            Found in lib/endpoints/class-wp-rest-terms-controller.php - About 1 day to fix

              Function addMixinsAndHelpers has 208 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  wp.api.utils.addMixinsAndHelpers = function( model, modelClassName, loadingObjects ) {
              
                      var hasDate = false,
              
                          /**
              Severity: Major
              Found in wp-api.js - About 1 day to fix

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

                    protected function prepare_item_for_database( $request ) {
                        $prepared_post = new stdClass;
                
                        // ID.
                        if ( isset( $request['id'] ) ) {
                Severity: Minor
                Found in lib/endpoints/class-wp-rest-posts-controller.php - About 7 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_item_schema has 148 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'                => 'comment',
                            'type'                 => 'object',
                Severity: Major
                Found in lib/endpoints/class-wp-rest-comments-controller.php - About 5 hrs 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

                    File plugin.php has 400 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    <?php
                    /**
                     * Plugin Name: WP REST API
                     * Description: JSON-based REST API for WordPress, originally developed as part of GSoC 2013.
                     * Author: WP REST API Team
                    Severity: Minor
                    Found in plugin.php - About 5 hrs to fix

                      Function constructFromSchema has 139 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                              constructFromSchema: function() {
                                  var routeModel = this, modelRoutes, collectionRoutes, schemaRoot, loadingObjects,
                      
                                  /**
                                   * Set up the model and collection name mapping options. As the schema is built, the
                      Severity: Major
                      Found in wp-api.js - About 5 hrs to fix

                        Similar blocks of code found in 2 locations. 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-taxonomies-controller.php and 1 other location - About 5 hrs to fix
                        lib/endpoints/class-wp-rest-post-statuses-controller.php on lines 13..36

                        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 185.

                        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

                        Similar blocks of code found in 2 locations. 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-post-statuses-controller.php and 1 other location - About 5 hrs to fix
                        lib/endpoints/class-wp-rest-taxonomies-controller.php on lines 13..36

                        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 185.

                        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

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

                            public function prepare_item_for_response( $post, $request ) {
                                $GLOBALS['post'] = $post;
                                setup_postdata( $post );
                        
                                $schema = $this->get_item_schema();
                        Severity: Minor
                        Found in lib/endpoints/class-wp-rest-posts-controller.php - About 5 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

                        Severity
                        Category
                        Status
                        Source
                        Language