gocodebox/lifterlms-rest

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

Summary

Maintainability
F
3 days
Test Coverage
A
98%

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

    protected function get_item_schema_base() {

        $schema = (array) parent::get_item_schema_base();

        $schema['properties']['auto_enroll'] = array(
Severity: Major
Found in includes/server/class-llms-rest-memberships-controller.php - About 6 hrs to fix

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

    <?php
    /**
     * REST Memberships Controller
     *
     * @package LifterLMS_REST/Classes/Controllers
    Severity: Minor
    Found in includes/server/class-llms-rest-memberships-controller.php - About 5 hrs to fix

      Function update_additional_object_fields has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function update_additional_object_fields( $membership, $request, $schema, $prepared_item, $creating = true ) {
              $error = new WP_Error();
      
              // Auto enroll.
              if ( ! empty( $schema['properties']['auto_enroll'] ) && isset( $request['auto_enroll'] ) ) {
      Severity: Minor
      Found in includes/server/class-llms-rest-memberships-controller.php - About 5 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 update_additional_object_fields has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function update_additional_object_fields( $membership, $request, $schema, $prepared_item, $creating = true ) {
              $error = new WP_Error();
      
              // Auto enroll.
              if ( ! empty( $schema['properties']['auto_enroll'] ) && isset( $request['auto_enroll'] ) ) {
      Severity: Major
      Found in includes/server/class-llms-rest-memberships-controller.php - About 2 hrs to fix

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

            protected function prepare_item_for_database( $request ) {
                $prepared_item = parent::prepare_item_for_database( $request );
                $schema        = $this->get_item_schema();
        
                // Restriction action.
        Severity: Minor
        Found in includes/server/class-llms-rest-memberships-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_object_for_response has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function prepare_object_for_response( $membership, $request ) {
                $data    = parent::prepare_object_for_response( $membership, $request );
                $context = $request->get_param( 'context' );
        
                // Auto enroll.
        Severity: Minor
        Found in includes/server/class-llms-rest-memberships-controller.php - About 1 hr to fix

          Method prepare_links has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function prepare_links( $membership, $request ) {
          
                  $links = parent::prepare_links( $membership, $request );
                  unset( $links['content'] );
                  $id = $membership->get( 'id' );
          Severity: Minor
          Found in includes/server/class-llms-rest-memberships-controller.php - About 1 hr to fix

            Method prepare_item_for_database has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function prepare_item_for_database( $request ) {
                    $prepared_item = parent::prepare_item_for_database( $request );
                    $schema        = $this->get_item_schema();
            
                    // Restriction action.
            Severity: Minor
            Found in includes/server/class-llms-rest-memberships-controller.php - About 1 hr to fix

              Method update_additional_object_fields has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  protected function update_additional_object_fields( $membership, $request, $schema, $prepared_item, $creating = true ) {
              Severity: Minor
              Found in includes/server/class-llms-rest-memberships-controller.php - About 35 mins to fix

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                        register_rest_route(
                            $this->namespace,
                            '/' . $this->rest_base . '/(?P<id>[\d]+)/enrollments',
                            array(
                                'args'   => array(
                Severity: Major
                Found in includes/server/class-llms-rest-memberships-controller.php and 1 other location - About 2 hrs to fix
                includes/server/class-llms-rest-courses-controller.php on lines 127..145

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

                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

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                        if ( ! empty( $schema['properties']['instructors'] ) ) {
                
                            $instructors = array();
                
                            if ( isset( $request['instructors'] ) ) {
                Severity: Major
                Found in includes/server/class-llms-rest-memberships-controller.php and 1 other location - About 2 hrs to fix
                includes/server/class-llms-rest-courses-controller.php on lines 834..856

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

                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

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                        if ( ! empty( $schema['properties']['sales_page_page_id'] ) && isset( $request['sales_page_page_id'] ) ) {
                            $page = get_post( $request['sales_page_page_id'] );
                            if ( $page && is_a( $page, 'WP_Post' ) ) {
                                $prepared_item['sales_page_content_page_id'] = $request['sales_page_page_id'];
                            } else {
                Severity: Minor
                Found in includes/server/class-llms-rest-memberships-controller.php and 1 other location - About 40 mins to fix
                includes/server/class-llms-rest-memberships-controller.php on lines 348..355

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

                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

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                        if ( ! empty( $schema['properties']['restriction_page_id'] ) && isset( $request['restriction_page_id'] ) ) {
                            $page = get_post( $request['restriction_page_id'] );
                            if ( $page && is_a( $page, 'WP_Post' ) ) {
                                $prepared_item['redirect_page_id'] = $request['restriction_page_id'];
                            } else {
                Severity: Minor
                Found in includes/server/class-llms-rest-memberships-controller.php and 1 other location - About 40 mins to fix
                includes/server/class-llms-rest-memberships-controller.php on lines 363..370

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

                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