woocommerce/woocommerce

View on GitHub
includes/cli/class-wc-cli-rest-command.php

Summary

Maintainability
D
1 day
Test Coverage

Function do_request has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    private function do_request( $method, $route, $assoc_args ) {
        wc_maybe_define_constant( 'REST_REQUEST', true );

        $request = new WP_REST_Request( $method, $route );
        if ( in_array( $method, array( 'POST', 'PUT' ), true ) ) {
Severity: Minor
Found in includes/cli/class-wc-cli-rest-command.php - About 3 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 do_request has 67 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function do_request( $method, $route, $assoc_args ) {
        wc_maybe_define_constant( 'REST_REQUEST', true );

        $request = new WP_REST_Request( $method, $route );
        if ( in_array( $method, array( 'POST', 'PUT' ), true ) ) {
Severity: Major
Found in includes/cli/class-wc-cli-rest-command.php - About 2 hrs to fix

    File class-wc-cli-rest-command.php has 276 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /**
     * WP_CLI_Rest_Command class file.
     *
     * @package WooCommerce\CLI
    Severity: Minor
    Found in includes/cli/class-wc-cli-rest-command.php - About 2 hrs to fix

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

          public function list_items( $args, $assoc_args ) {
              if ( ! empty( $assoc_args['format'] ) && 'count' === $assoc_args['format'] ) {
                  $method = 'HEAD';
              } else {
                  $method = 'GET';
      Severity: Minor
      Found in includes/cli/class-wc-cli-rest-command.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 list_items has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function list_items( $args, $assoc_args ) {
              if ( ! empty( $assoc_args['format'] ) && 'count' === $assoc_args['format'] ) {
                  $method = 'HEAD';
              } else {
                  $method = 'GET';
      Severity: Minor
      Found in includes/cli/class-wc-cli-rest-command.php - About 1 hr to fix

        Function get_formatter has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function get_formatter( &$assoc_args ) {
                if ( ! empty( $assoc_args['fields'] ) ) {
                    if ( is_string( $assoc_args['fields'] ) ) {
                        $fields = explode( ',', $assoc_args['fields'] );
                    } else {
        Severity: Minor
        Found in includes/cli/class-wc-cli-rest-command.php - About 45 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 delete_item has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            public function delete_item( $args, $assoc_args ) {
                list( $status, $body ) = $this->do_request( 'DELETE', $this->get_filled_route( $args ), $assoc_args );
                $object_id = isset( $body['id'] ) ? $body['id'] : '';
                if ( ! $object_id && isset( $body['slug'] ) ) {
                    $object_id = $body['slug'];
        Severity: Minor
        Found in includes/cli/class-wc-cli-rest-command.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 decode_json has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function decode_json( $arr ) {
                foreach ( $arr as $key => $value ) {
                    if ( '[' === substr( $value, 0, 1 ) || '{' === substr( $value, 0, 1 ) ) {
                        $arr[ $key ] = json_decode( $value, true );
                    } else {
        Severity: Minor
        Found in includes/cli/class-wc-cli-rest-command.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

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

            public function get_item( $args, $assoc_args ) {
                $route                           = $this->get_filled_route( $args );
                list( $status, $body, $headers ) = $this->do_request( 'GET', $route, $assoc_args );
        
                if ( ! empty( $assoc_args['fields'] ) ) {
        Severity: Minor
        Found in includes/cli/class-wc-cli-rest-command.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