woothemes/woocommerce

View on GitHub
includes/legacy/api/v1/class-wc-api-server.php

Summary

Maintainability
F
1 wk
Test Coverage

File class-wc-api-server.php has 383 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * WooCommerce API
 *
 * Handles REST API requests
Severity: Minor
Found in includes/legacy/api/v1/class-wc-api-server.php - About 5 hrs to fix

    Function dispatch has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
    Open

        public function dispatch() {
    
            switch ( $this->method ) {
    
                case 'HEAD':
    Severity: Minor
    Found in includes/legacy/api/v1/class-wc-api-server.php - About 4 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_index has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        public function get_index() {
    
            // General site data
            $available = array(
                'store' => array(
    Severity: Minor
    Found in includes/legacy/api/v1/class-wc-api-server.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 dispatch has 62 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function dispatch() {
    
            switch ( $this->method ) {
    
                case 'HEAD':
    Severity: Major
    Found in includes/legacy/api/v1/class-wc-api-server.php - About 2 hrs to fix

      Method get_index has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function get_index() {
      
              // General site data
              $available = array(
                  'store' => array(
      Severity: Minor
      Found in includes/legacy/api/v1/class-wc-api-server.php - About 1 hr to fix

        Method add_pagination_headers has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function add_pagination_headers( $query ) {
        
                // WP_User_Query
                if ( is_a( $query, 'WP_User_Query' ) ) {
        
        
        Severity: Minor
        Found in includes/legacy/api/v1/class-wc-api-server.php - About 1 hr to fix

          Function add_pagination_headers has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public function add_pagination_headers( $query ) {
          
                  // WP_User_Query
                  if ( is_a( $query, 'WP_User_Query' ) ) {
          
          
          Severity: Minor
          Found in includes/legacy/api/v1/class-wc-api-server.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 serve_request has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public function serve_request() {
          
                  do_action( 'woocommerce_api_server_before_serve', $this );
          
                  $this->header( 'Content-Type', $this->handler->get_content_type(), true );
          Severity: Minor
          Found in includes/legacy/api/v1/class-wc-api-server.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 __construct has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function __construct( $path ) {
          
                  if ( empty( $path ) ) {
                      if ( isset( $_SERVER['PATH_INFO'] ) ) {
                          $path = $_SERVER['PATH_INFO'];
          Severity: Minor
          Found in includes/legacy/api/v1/class-wc-api-server.php - About 1 hr to fix

            Function __construct has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                public function __construct( $path ) {
            
                    if ( empty( $path ) ) {
                        if ( isset( $_SERVER['PATH_INFO'] ) ) {
                            $path = $_SERVER['PATH_INFO'];
            Severity: Minor
            Found in includes/legacy/api/v1/class-wc-api-server.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 format_datetime has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                public function format_datetime( $timestamp, $convert_to_utc = false, $convert_to_gmt = false ) {
                    if ( $convert_to_gmt ) {
                        if ( is_numeric( $timestamp ) ) {
                            $timestamp = date( 'Y-m-d H:i:s', $timestamp );
                        }
            Severity: Minor
            Found in includes/legacy/api/v1/class-wc-api-server.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 sort_callback_params has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function sort_callback_params( $callback, $provided ) {
                    if ( is_array( $callback ) ) {
                        $ref_func = new ReflectionMethod( $callback[0], $callback[1] );
                    } else {
                        $ref_func = new ReflectionFunction( $callback );
            Severity: Minor
            Found in includes/legacy/api/v1/class-wc-api-server.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 call_user_func_array( $callback, $params );
            Severity: Major
            Found in includes/legacy/api/v1/class-wc-api-server.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return new WP_Error( 'woocommerce_api_no_route', __( 'No route was found matching the URL and request method', 'woocommerce' ), array( 'status' => 404 ) );
              Severity: Major
              Found in includes/legacy/api/v1/class-wc-api-server.php - About 30 mins to fix

                Identical blocks of code found in 3 locations. Consider refactoring.
                Open

                    public function dispatch() {
                
                        switch ( $this->method ) {
                
                            case 'HEAD':
                Severity: Major
                Found in includes/legacy/api/v1/class-wc-api-server.php and 2 other locations - About 3 days to fix
                includes/legacy/api/v2/class-wc-api-server.php on lines 293..376
                includes/legacy/api/v3/class-wc-api-server.php on lines 293..376

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

                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

                Identical blocks of code found in 3 locations. Consider refactoring.
                Open

                    public function serve_request() {
                
                        do_action( 'woocommerce_api_server_before_serve', $this );
                
                        $this->header( 'Content-Type', $this->handler->get_content_type(), true );
                Severity: Major
                Found in includes/legacy/api/v1/class-wc-api-server.php and 2 other locations - About 1 day to fix
                includes/legacy/api/v2/class-wc-api-server.php on lines 202..247
                includes/legacy/api/v3/class-wc-api-server.php on lines 202..247

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

                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

                Identical blocks of code found in 3 locations. Consider refactoring.
                Open

                    public function format_datetime( $timestamp, $convert_to_utc = false, $convert_to_gmt = false ) {
                        if ( $convert_to_gmt ) {
                            if ( is_numeric( $timestamp ) ) {
                                $timestamp = date( 'Y-m-d H:i:s', $timestamp );
                            }
                Severity: Major
                Found in includes/legacy/api/v1/class-wc-api-server.php and 2 other locations - About 6 hrs to fix
                includes/legacy/api/v2/class-wc-api-server.php on lines 718..751
                includes/legacy/api/v3/class-wc-api-server.php on lines 720..753

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

                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

                Identical blocks of code found in 3 locations. Consider refactoring.
                Open

                    public function parse_datetime( $datetime ) {
                
                        // Strip millisecond precision (a full stop followed by one or more digits)
                        if ( strpos( $datetime, '.' ) !== false ) {
                            $datetime = preg_replace( '/\.\d+/', '', $datetime );
                Severity: Major
                Found in includes/legacy/api/v1/class-wc-api-server.php and 2 other locations - About 2 hrs to fix
                includes/legacy/api/v2/class-wc-api-server.php on lines 686..707
                includes/legacy/api/v3/class-wc-api-server.php on lines 688..709

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

                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

                Identical blocks of code found in 3 locations. Consider refactoring.
                Open

                    public function get_headers( $server ) {
                        $headers = array();
                        // CONTENT_* headers are not prefixed with HTTP_
                        $additional = array( 'CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true );
                
                
                Severity: Major
                Found in includes/legacy/api/v1/class-wc-api-server.php and 2 other locations - About 1 hr to fix
                includes/legacy/api/v2/class-wc-api-server.php on lines 760..774
                includes/legacy/api/v3/class-wc-api-server.php on lines 762..776

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

                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

                Identical blocks of code found in 3 locations. Consider refactoring.
                Open

                    public function get_routes() {
                
                        // index added by default
                        $endpoints = array(
                
                
                Severity: Major
                Found in includes/legacy/api/v1/class-wc-api-server.php and 2 other locations - About 1 hr to fix
                includes/legacy/api/v2/class-wc-api-server.php on lines 267..285
                includes/legacy/api/v3/class-wc-api-server.php on lines 267..285

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

                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

                Identical blocks of code found in 3 locations. Consider refactoring.
                Open

                    public function link_header( $rel, $link, $other = array() ) {
                
                        $header = sprintf( '<%s>; rel="%s"', $link, esc_attr( $rel ) );
                
                        foreach ( $other as $key => $value ) {
                Severity: Major
                Found in includes/legacy/api/v1/class-wc-api-server.php and 2 other locations - About 1 hr to fix
                includes/legacy/api/v2/class-wc-api-server.php on lines 547..562
                includes/legacy/api/v3/class-wc-api-server.php on lines 549..564

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

                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

                Identical blocks of code found in 3 locations. Consider refactoring.
                Open

                    public function check_authentication() {
                
                        // allow plugins to remove default authentication or add their own authentication
                        $user = apply_filters( 'woocommerce_api_check_authentication', null, $this );
                
                
                Severity: Major
                Found in includes/legacy/api/v1/class-wc-api-server.php and 2 other locations - About 1 hr to fix
                includes/legacy/api/v2/class-wc-api-server.php on lines 151..169
                includes/legacy/api/v3/class-wc-api-server.php on lines 151..169

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

                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

                There are no issues that match your filters.

                Category
                Status