woothemes/woocommerce

View on GitHub
includes/rest-api/Controllers/Version3/class-wc-rest-terms-controller.php

Summary

Maintainability
F
3 days
Test Coverage

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

<?php
/**
 * Abstract Rest Terms Controller
 *
 * @package WooCommerce\RestApi

    Method register_routes has 80 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function register_routes() {
            register_rest_route(
                $this->namespace,
                '/' . $this->rest_base,
                array(

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

          public function get_collection_params() {
              $params = parent::get_collection_params();
      
              $params['context']['default'] = 'view';
      
      

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

            public function get_items( $request ) {
                $taxonomy      = $this->get_taxonomy( $request );
                $prepared_args = array(
                    'exclude'    => $request['exclude'],
                    'include'    => $request['include'],

        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_items has 71 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function get_items( $request ) {
                $taxonomy      = $this->get_taxonomy( $request );
                $prepared_args = array(
                    'exclude'    => $request['exclude'],
                    'include'    => $request['include'],

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

              public function create_item( $request ) {
                  $taxonomy = $this->get_taxonomy( $request );
                  $name     = $request['name'];
                  $args     = array();
                  $schema   = $this->get_item_schema();

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

                public function update_item( $request ) {
                    $taxonomy      = $this->get_taxonomy( $request );
                    $term          = get_term( (int) $request['id'], $taxonomy );
                    $schema        = $this->get_item_schema();
                    $prepared_args = array();

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

                  public function update_item( $request ) {
                      $taxonomy      = $this->get_taxonomy( $request );
                      $term          = get_term( (int) $request['id'], $taxonomy );
                      $schema        = $this->get_item_schema();
                      $prepared_args = array();

              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 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function create_item( $request ) {
                      $taxonomy = $this->get_taxonomy( $request );
                      $name     = $request['name'];
                      $args     = array();
                      $schema   = $this->get_item_schema();

              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_terms_for_product has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function get_terms_for_product( $prepared_args, $request ) {
                      $taxonomy = $this->get_taxonomy( $request );
              
                      $query_result = get_the_terms( $prepared_args['product'], $taxonomy );
                      if ( empty( $query_result ) ) {

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

                    protected function get_terms_for_product( $prepared_args, $request ) {
                        $taxonomy = $this->get_taxonomy( $request );
                
                        $query_result = get_the_terms( $prepared_args['product'], $taxonomy );
                        if ( empty( $query_result ) ) {

                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 check_permissions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function check_permissions( $request, $context = 'read' ) {
                        // Get taxonomy.
                        $taxonomy = $this->get_taxonomy( $request );
                        if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) {
                            return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Taxonomy does not exist.', 'woocommerce' ), array( 'status' => 404 ) );

                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