gocodebox/lifterlms-rest

View on GitHub

Showing 191 of 191 total issues

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

    protected function prepare_item_for_database( $request ) {

        $prepared = array();

        if ( isset( $request['id'] ) ) {
Severity: Minor
Found in includes/server/class-llms-rest-api-keys-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

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

    protected function get_objects_query( $prepared, $request ) {

        if ( 'id' === $prepared['orderby'] ) {
            $prepared['orderby'] = 'ID';
        } elseif ( 'registered_date' === $prepared['orderby'] ) {
Severity: Minor
Found in includes/abstracts/class-llms-rest-users-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

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

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

        if ( ! empty( $schema['properties']['restricted_message'] ) && isset( $request['restricted_message'] ) ) {
            if ( is_string( $request['restricted_message'] ) ) {
                $prepared_item['content_restricted_message'] = $request['restricted_message'];
            } elseif ( isset( $request['restricted_message']['raw'] ) ) {
                $prepared_item['content_restricted_message'] = $request['restricted_message']['raw'];
Severity: Major
Found in includes/server/class-llms-rest-courses-controller.php and 8 other locations - About 30 mins to fix
includes/abstracts/class-llms-rest-posts-controller.php on lines 1026..1032
includes/abstracts/class-llms-rest-posts-controller.php on lines 1035..1041
includes/server/class-llms-rest-courses-controller.php on lines 730..736
includes/server/class-llms-rest-courses-controller.php on lines 753..759
includes/server/class-llms-rest-courses-controller.php on lines 930..936
includes/server/class-llms-rest-courses-controller.php on lines 938..944
includes/server/class-llms-rest-courses-controller.php on lines 947..953
includes/server/class-llms-rest-courses-controller.php on lines 955..961

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

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 9 locations. Consider refactoring.
Open

        if ( ! empty( $schema['properties']['length'] ) && isset( $request['length'] ) ) {
            if ( is_string( $request['length'] ) ) {
                $prepared_item['length'] = $request['length'];
            } elseif ( isset( $request['length']['raw'] ) ) {
                $prepared_item['length'] = $request['length']['raw'];
Severity: Major
Found in includes/server/class-llms-rest-courses-controller.php and 8 other locations - About 30 mins to fix
includes/abstracts/class-llms-rest-posts-controller.php on lines 1026..1032
includes/abstracts/class-llms-rest-posts-controller.php on lines 1035..1041
includes/server/class-llms-rest-courses-controller.php on lines 730..736
includes/server/class-llms-rest-courses-controller.php on lines 744..750
includes/server/class-llms-rest-courses-controller.php on lines 930..936
includes/server/class-llms-rest-courses-controller.php on lines 938..944
includes/server/class-llms-rest-courses-controller.php on lines 947..953
includes/server/class-llms-rest-courses-controller.php on lines 955..961

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

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 9 locations. Consider refactoring.
Open

        if ( ! empty( $schema['properties']['access_opens_message'] ) && isset( $request['access_opens_message'] ) ) {
            if ( is_string( $request['access_opens_message'] ) ) {
                $to_set['course_opens_message'] = $request['access_opens_message'];
            } elseif ( isset( $request['access_opens_message']['raw'] ) ) {
                $to_set['course_opens_message'] = $request['access_opens_message']['raw'];
Severity: Major
Found in includes/server/class-llms-rest-courses-controller.php and 8 other locations - About 30 mins to fix
includes/abstracts/class-llms-rest-posts-controller.php on lines 1026..1032
includes/abstracts/class-llms-rest-posts-controller.php on lines 1035..1041
includes/server/class-llms-rest-courses-controller.php on lines 730..736
includes/server/class-llms-rest-courses-controller.php on lines 744..750
includes/server/class-llms-rest-courses-controller.php on lines 753..759
includes/server/class-llms-rest-courses-controller.php on lines 938..944
includes/server/class-llms-rest-courses-controller.php on lines 947..953
includes/server/class-llms-rest-courses-controller.php on lines 955..961

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

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 9 locations. Consider refactoring.
Open

        if ( ! empty( $schema['properties']['enrollment_opens_message'] ) && isset( $request['enrollment_opens_message'] ) ) {
            if ( is_string( $request['enrollment_opens_message'] ) ) {
                $to_set['enrollment_opens_message'] = $request['enrollment_opens_message'];
            } elseif ( isset( $request['enrollment_opens_message']['raw'] ) ) {
                $to_set['enrollment_opens_message'] = $request['enrollment_opens_message']['raw'];
Severity: Major
Found in includes/server/class-llms-rest-courses-controller.php and 8 other locations - About 30 mins to fix
includes/abstracts/class-llms-rest-posts-controller.php on lines 1026..1032
includes/abstracts/class-llms-rest-posts-controller.php on lines 1035..1041
includes/server/class-llms-rest-courses-controller.php on lines 730..736
includes/server/class-llms-rest-courses-controller.php on lines 744..750
includes/server/class-llms-rest-courses-controller.php on lines 753..759
includes/server/class-llms-rest-courses-controller.php on lines 930..936
includes/server/class-llms-rest-courses-controller.php on lines 938..944
includes/server/class-llms-rest-courses-controller.php on lines 955..961

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

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 9 locations. Consider refactoring.
Open

        if ( ! empty( $schema['properties']['enrollment_closes_message'] ) && isset( $request['enrollment_closes_message'] ) ) {
            if ( is_string( $request['enrollment_closes_message'] ) ) {
                $to_set['enrollment_closed_message'] = $request['enrollment_closes_message'];
            } elseif ( isset( $request['enrollment_closes_message']['raw'] ) ) {
                $to_set['enrollment_closed_message'] = $request['enrollment_closes_message']['raw'];
Severity: Major
Found in includes/server/class-llms-rest-courses-controller.php and 8 other locations - About 30 mins to fix
includes/abstracts/class-llms-rest-posts-controller.php on lines 1026..1032
includes/abstracts/class-llms-rest-posts-controller.php on lines 1035..1041
includes/server/class-llms-rest-courses-controller.php on lines 730..736
includes/server/class-llms-rest-courses-controller.php on lines 744..750
includes/server/class-llms-rest-courses-controller.php on lines 753..759
includes/server/class-llms-rest-courses-controller.php on lines 930..936
includes/server/class-llms-rest-courses-controller.php on lines 938..944
includes/server/class-llms-rest-courses-controller.php on lines 947..953

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

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 9 locations. Consider refactoring.
Open

        if ( ! empty( $schema['properties']['content'] ) && isset( $request['content'] ) ) {
            if ( is_string( $request['content'] ) ) {
                $prepared_item['post_content'] = $request['content'];
            } elseif ( isset( $request['content']['raw'] ) ) {
                $prepared_item['post_content'] = $request['content']['raw'];
Severity: Major
Found in includes/abstracts/class-llms-rest-posts-controller.php and 8 other locations - About 30 mins to fix
includes/abstracts/class-llms-rest-posts-controller.php on lines 1035..1041
includes/server/class-llms-rest-courses-controller.php on lines 730..736
includes/server/class-llms-rest-courses-controller.php on lines 744..750
includes/server/class-llms-rest-courses-controller.php on lines 753..759
includes/server/class-llms-rest-courses-controller.php on lines 930..936
includes/server/class-llms-rest-courses-controller.php on lines 938..944
includes/server/class-llms-rest-courses-controller.php on lines 947..953
includes/server/class-llms-rest-courses-controller.php on lines 955..961

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

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 9 locations. Consider refactoring.
Open

        if ( ! empty( $schema['properties']['capacity_message'] ) && isset( $request['capacity_message'] ) ) {
            if ( is_string( $request['capacity_message'] ) ) {
                $prepared_item['capacity_message'] = $request['capacity_message'];
            } elseif ( isset( $request['capacity_message']['raw'] ) ) {
                $prepared_item['capacity_message'] = $request['capacity_message']['raw'];
Severity: Major
Found in includes/server/class-llms-rest-courses-controller.php and 8 other locations - About 30 mins to fix
includes/abstracts/class-llms-rest-posts-controller.php on lines 1026..1032
includes/abstracts/class-llms-rest-posts-controller.php on lines 1035..1041
includes/server/class-llms-rest-courses-controller.php on lines 744..750
includes/server/class-llms-rest-courses-controller.php on lines 753..759
includes/server/class-llms-rest-courses-controller.php on lines 930..936
includes/server/class-llms-rest-courses-controller.php on lines 938..944
includes/server/class-llms-rest-courses-controller.php on lines 947..953
includes/server/class-llms-rest-courses-controller.php on lines 955..961

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

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 9 locations. Consider refactoring.
Open

        if ( ! empty( $schema['properties']['access_closes_message'] ) && isset( $request['access_closes_message'] ) ) {
            if ( is_string( $request['access_closes_message'] ) ) {
                $to_set['course_closed_message'] = $request['access_closes_message'];
            } elseif ( isset( $request['access_closes_message']['raw'] ) ) {
                $to_set['course_closed_message'] = $request['access_closes_message']['raw'];
Severity: Major
Found in includes/server/class-llms-rest-courses-controller.php and 8 other locations - About 30 mins to fix
includes/abstracts/class-llms-rest-posts-controller.php on lines 1026..1032
includes/abstracts/class-llms-rest-posts-controller.php on lines 1035..1041
includes/server/class-llms-rest-courses-controller.php on lines 730..736
includes/server/class-llms-rest-courses-controller.php on lines 744..750
includes/server/class-llms-rest-courses-controller.php on lines 753..759
includes/server/class-llms-rest-courses-controller.php on lines 930..936
includes/server/class-llms-rest-courses-controller.php on lines 947..953
includes/server/class-llms-rest-courses-controller.php on lines 955..961

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

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 9 locations. Consider refactoring.
Open

        if ( ! empty( $schema['properties']['excerpt'] ) && isset( $request['excerpt'] ) ) {
            if ( is_string( $request['excerpt'] ) ) {
                $prepared_item['post_excerpt'] = $request['excerpt'];
            } elseif ( isset( $request['excerpt']['raw'] ) ) {
                $prepared_item['post_excerpt'] = $request['excerpt']['raw'];
Severity: Major
Found in includes/abstracts/class-llms-rest-posts-controller.php and 8 other locations - About 30 mins to fix
includes/abstracts/class-llms-rest-posts-controller.php on lines 1026..1032
includes/server/class-llms-rest-courses-controller.php on lines 730..736
includes/server/class-llms-rest-courses-controller.php on lines 744..750
includes/server/class-llms-rest-courses-controller.php on lines 753..759
includes/server/class-llms-rest-courses-controller.php on lines 930..936
includes/server/class-llms-rest-courses-controller.php on lines 938..944
includes/server/class-llms-rest-courses-controller.php on lines 947..953
includes/server/class-llms-rest-courses-controller.php on lines 955..961

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

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

Avoid too many return statements within this method.
Open

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

    Avoid too many return statements within this method.
    Open

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

      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 $fields_update;
        Severity: Major
        Found in includes/abstracts/class-llms-rest-posts-controller.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

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

            Avoid too many return statements within this method.
            Open

                    return false;
            Severity: Major
            Found in includes/abstracts/class-llms-rest-posts-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
                  Severity
                  Category
                  Status
                  Source
                  Language