gocodebox/lifterlms

View on GitHub
includes/models/model.llms.access.plan.php

Summary

Maintainability
D
2 days
Test Coverage
A
95%

File model.llms.access.plan.php has 331 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * LifterLMS Access Plan Model
 *
 * @package LifterLMS/Models/Classes
Severity: Minor
Found in includes/models/model.llms.access.plan.php - About 3 hrs to fix

    LLMS_Access_Plan has 30 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class LLMS_Access_Plan extends LLMS_Post_Model {
    
        /**
         * Map of meta properties => type.
         *
    Severity: Minor
    Found in includes/models/model.llms.access.plan.php - About 3 hrs to fix

      Function get_price_with_coupon has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          public function get_price_with_coupon( $key, $coupon_id, $price_args = array(), $format = 'html' ) {
      
              // Allow id or instance to be passed for $coupon_id.
              if ( $coupon_id instanceof LLMS_Coupon ) {
                  $coupon = $coupon_id;
      Severity: Minor
      Found in includes/models/model.llms.access.plan.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

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

          public function get_price_with_coupon( $key, $coupon_id, $price_args = array(), $format = 'html' ) {
      
              // Allow id or instance to be passed for $coupon_id.
              if ( $coupon_id instanceof LLMS_Coupon ) {
                  $coupon = $coupon_id;
      Severity: Minor
      Found in includes/models/model.llms.access.plan.php - About 1 hr to fix

        Function get_checkout_url has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            public function get_checkout_url( $check_availability = true ) {
        
                $ret       = '#llms-plan-locked';
                $available = $this->is_available_to_user( get_current_user_id() );
        
        
        Severity: Minor
        Found in includes/models/model.llms.access.plan.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 get_checkout_url has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function get_checkout_url( $check_availability = true ) {
        
                $ret       = '#llms-plan-locked';
                $available = $this->is_available_to_user( get_current_user_id() );
        
        
        Severity: Minor
        Found in includes/models/model.llms.access.plan.php - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

                      if ( ! $start && ! $end ) {
          
                          $ret = true;
          
                          // Start and end.
          Severity: Major
          Found in includes/models/model.llms.access.plan.php - About 40 mins to fix

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

                public function is_on_sale() {
            
                    $ret = false;
            
                    if ( llms_parse_bool( $this->get( 'on_sale' ) ) ) {
            Severity: Minor
            Found in includes/models/model.llms.access.plan.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 is_available_to_user has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function is_available_to_user( $user_id = null ) {
            
                    $user_id = empty( $user_id ) ? get_current_user_id() : $user_id;
            
                    $access = true;
            Severity: Minor
            Found in includes/models/model.llms.access.plan.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 calculate_redirection_url has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                private function calculate_redirection_url( $redirect_type ) {
            
                    $available = $this->is_available_to_user( get_current_user_id() );
            
                    if ( ! $available && 'no' === $this->get( 'checkout_redirect_forced' ) ) {
            Severity: Minor
            Found in includes/models/model.llms.access.plan.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_schedule_details has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public function get_schedule_details() {
            
                    $ret = '';
            
                    $period    = $this->get( 'period' );
            Severity: Minor
            Found in includes/models/model.llms.access.plan.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

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

                protected $properties = array(
                    'access_expiration'         => 'string',
                    'access_expires'            => 'string',
                    'access_length'             => 'absint',
                    'access_period'             => 'string',
            Severity: Major
            Found in includes/models/model.llms.access.plan.php and 1 other location - About 3 hrs to fix
            includes/models/model.llms.course.php on lines 64..99

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

            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