woothemes/woocommerce

View on GitHub
includes/rest-api/Controllers/Version1/class-wc-rest-report-sales-v1-controller.php

Summary

Maintainability
D
1 day
Test Coverage

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

    public function prepare_item_for_response( $_, $request ) {
        // Set date filtering.
        $filter = array(
            'period'   => $request['period'],
            'date_min' => $request['date_min'],

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

    public function prepare_item_for_response( $_, $request ) {
        // Set date filtering.
        $filter = array(
            'period'   => $request['period'],
            'date_min' => $request['date_min'],

    Method get_item_schema has 77 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'      => 'sales_report',
                'type'       => 'object',

      File class-wc-rest-report-sales-v1-controller.php has 259 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      /**
       * REST API Reports controller
       *
       * Handles requests to the reports/sales endpoint.

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

            protected function setup_report( $filter ) {
                include_once( WC()->plugin_path() . '/includes/admin/reports/class-wc-admin-report.php' );
                include_once( WC()->plugin_path() . '/includes/admin/reports/class-wc-report-sales-by-date.php' );
        
                $this->report = new WC_Report_Sales_By_Date();

        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