gocodebox/lifterlms-rest

View on GitHub
includes/abstracts/class-llms-rest-controller.php

Summary

Maintainability
D
2 days
Test Coverage
A
93%

File class-llms-rest-controller.php has 456 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Base REST Controller
 *
 * @package LifterLMS_REST/Abstracts
Severity: Minor
Found in includes/abstracts/class-llms-rest-controller.php - About 6 hrs to fix

    Function prepare_collection_query_search_args has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function prepare_collection_query_search_args( $prepared, $request ) {
    
            // Search?
            if ( ! empty( $prepared['search'] ) ) {
    
    
    Severity: Minor
    Found in includes/abstracts/class-llms-rest-controller.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

    LLMS_REST_Controller has 29 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class LLMS_REST_Controller extends LLMS_REST_Controller_Stubs {
    
        /**
         * Endpoint namespace.
         *
    Severity: Minor
    Found in includes/abstracts/class-llms-rest-controller.php - About 3 hrs to fix

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

          public function register_routes() {
      
              register_rest_route(
                  $this->namespace,
                  '/' . $this->rest_base,
      Severity: Minor
      Found in includes/abstracts/class-llms-rest-controller.php - About 2 hrs to fix

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

            public function get_collection_params() {
        
                $query_params = parent::get_collection_params();
        
                $query_params['context']['default'] = 'view';
        Severity: Minor
        Found in includes/abstracts/class-llms-rest-controller.php - About 1 hr to fix

          Method prepare_collection_query_search_args has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function prepare_collection_query_search_args( $prepared, $request ) {
          
                  // Search?
                  if ( ! empty( $prepared['search'] ) ) {
          
          
          Severity: Minor
          Found in includes/abstracts/class-llms-rest-controller.php - About 1 hr to fix

            Function add_header_pagination has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function add_header_pagination( $response, $pagination, $request ) {
            
                    $response->header( 'X-WP-Total', $pagination['total_results'] );
                    $response->header( 'X-WP-TotalPages', $pagination['total_pages'] );
            
            
            Severity: Minor
            Found in includes/abstracts/class-llms-rest-controller.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 $response;
            Severity: Major
            Found in includes/abstracts/class-llms-rest-controller.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return $prepared;
              Severity: Major
              Found in includes/abstracts/class-llms-rest-controller.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return $response;
                Severity: Major
                Found in includes/abstracts/class-llms-rest-controller.php - About 30 mins to fix

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

                      protected function prepare_collection_items_for_response( $objects, $request ) {
                  
                          $items = array();
                  
                          foreach ( $objects as $object ) {
                  Severity: Minor
                  Found in includes/abstracts/class-llms-rest-controller.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