gocodebox/lifterlms-rest

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

Summary

Maintainability
F
4 days
Test Coverage
A
93%

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

<?php
/**
 * REST Enrollments Controller.
 *
 * @package LLMS_REST
Severity: Major
Found in includes/server/class-llms-rest-enrollments-controller.php - About 1 day to fix

    LLMS_REST_Enrollments_Controller has 34 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class LLMS_REST_Enrollments_Controller extends LLMS_REST_Controller {
    
        /**
         * Route base.
         *
    Severity: Minor
    Found in includes/server/class-llms-rest-enrollments-controller.php - About 4 hrs to fix

      Method get_objects_query has 103 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function get_objects_query( $query_args, $request = null ) {
      
              global $wpdb;
      
              // Maybe limit the query results depending on the page param.
      Severity: Major
      Found in includes/server/class-llms-rest-enrollments-controller.php - About 4 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/server/class-llms-rest-enrollments-controller.php - About 2 hrs to fix

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

              protected function get_item_schema_base() {
          
                  $schema = array(
                      '$schema'    => 'http://json-schema.org/draft-04/schema#',
                      'title'      => 'students-enrollments',
          Severity: Minor
          Found in includes/server/class-llms-rest-enrollments-controller.php - About 2 hrs to fix

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

                public function update_item( $request ) {
            
                    $student_id = (int) $request['id'];
                    $post_id    = (int) $request['post_id'];
            
            
            Severity: Minor
            Found in includes/server/class-llms-rest-enrollments-controller.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 update_item has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function update_item( $request ) {
            
                    $student_id = (int) $request['id'];
                    $post_id    = (int) $request['post_id'];
            
            
            Severity: Minor
            Found in includes/server/class-llms-rest-enrollments-controller.php - About 1 hr to fix

              Function get_objects_query has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function get_objects_query( $query_args, $request = null ) {
              
                      global $wpdb;
              
                      // Maybe limit the query results depending on the page param.
              Severity: Minor
              Found in includes/server/class-llms-rest-enrollments-controller.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 prepare_links has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function prepare_links( $enrollment, $request ) {
              
                      $links = array(
                          'self'       => array(
                              'href' => rest_url(
              Severity: Minor
              Found in includes/server/class-llms-rest-enrollments-controller.php - About 1 hr to fix

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

                    public function create_item( $request ) {
                
                        $user_id = (int) $request['id'];
                        $post_id = (int) $request['post_id'];
                
                
                Severity: Minor
                Found in includes/server/class-llms-rest-enrollments-controller.php - About 1 hr to fix

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

                      protected function prepare_items_query( $prepared_args = array(), $request = null ) {
                  
                          $query_args = array();
                  
                          foreach ( $prepared_args as $key => $value ) {
                  Severity: Minor
                  Found in includes/server/class-llms-rest-enrollments-controller.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

                  Avoid too many return statements within this method.
                  Open

                                  return llms_rest_server_error( __( 'The enrollment status could not be updated', 'lifterlms' ) );
                  Severity: Major
                  Found in includes/server/class-llms-rest-enrollments-controller.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

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

                      Avoid too many return statements within this method.
                      Open

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

                        Avoid too many return statements within this method.
                        Open

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

                          Avoid too many return statements within this method.
                          Open

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

                            Avoid too many return statements within this method.
                            Open

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

                              Avoid too many return statements within this method.
                              Open

                                              return llms_rest_server_error( __( 'The enrollment creation date could not be updated', 'lifterlms' ) );
                              Severity: Major
                              Found in includes/server/class-llms-rest-enrollments-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/server/class-llms-rest-enrollments-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

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

                                    public function create_item( $request ) {
                                
                                        $user_id = (int) $request['id'];
                                        $post_id = (int) $request['post_id'];
                                
                                
                                Severity: Minor
                                Found in includes/server/class-llms-rest-enrollments-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