Noosfero/noosfero

View on GitHub
plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb

Summary

Maintainability
C
1 day
Test Coverage

Class Cycle has 34 methods (exceeds 20 allowed). Consider refactoring.
Open

class OrdersCyclePlugin::Cycle < ApplicationRecord
  attr_accessible :profile, :status, :name, :description, :opening_message

  attr_accessible :start, :finish, :delivery_start, :delivery_finish
  attr_accessible :start_date, :start_time, :finish_date, :finish_time, :delivery_start_date, :delivery_start_time, :delivery_finish_date, :delivery_finish_time,
Severity: Minor
Found in plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb - About 4 hrs to fix

    File cycle.rb has 252 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class OrdersCyclePlugin::Cycle < ApplicationRecord
      attr_accessible :profile, :status, :name, :description, :opening_message
    
      attr_accessible :start, :finish, :delivery_start, :delivery_finish
      attr_accessible :start_date, :start_time, :finish_date, :finish_time, :delivery_start_date, :delivery_start_time, :delivery_finish_date, :delivery_finish_time,
    Severity: Minor
    Found in plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb - About 2 hrs to fix

      Method update_orders_status has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def update_orders_status
            return if self.new? || (self.status_was == "new")
            return if self.status_was == self.status
      
            # Don't rewind confirmed sales
      Severity: Minor
      Found in plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb - 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 validate_delivery_dates has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def validate_delivery_dates
            return if self.new? || delivery_start.nil? || delivery_finish.nil?
      
            errors.add :base, I18n.t("orders_cycle_plugin.models.cycle.invalid_delivery_peri") unless delivery_start < delivery_finish
            errors.add :base, I18n.t("orders_cycle_plugin.models.cycle.delivery_period_befor") unless finish <= delivery_start
      Severity: Minor
      Found in plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb - 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

            unless (self.status_was == "orders") && (self.status == "edition")
              sale_status_was = SaleStatusMap[self.status_was]
              new_sale_status = SaleStatusMap[self.status]
              self.delay.update_sales_status sale_status_was, new_sale_status unless sale_status_was == new_sale_status
            end
      Severity: Minor
      Found in plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb and 1 other location - About 25 mins to fix
      plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb on lines 303..307

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

      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

            unless (self.status_was == "receipts") && (self.status == "purchases")
              purchase_status_was = PurchaseStatusMap[self.status_was]
              new_purchase_status = PurchaseStatusMap[self.status]
              self.delay.update_purchases_status purchase_status_was, new_purchase_status unless purchase_status_was == new_purchase_status
            end
      Severity: Minor
      Found in plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb and 1 other location - About 25 mins to fix
      plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb on lines 296..300

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

      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

        def orders?
          now = DateTime.now
          status == "orders" && ((self.start <= now && self.finish.nil?) || (self.start <= now && self.finish >= now))
        end
      Severity: Minor
      Found in plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb and 1 other location - About 20 mins to fix
      plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb on lines 207..210

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

      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

        def delivery?
          now = DateTime.now
          status == "delivery" && ((self.delivery_start <= now && self.delivery_finish.nil?) || (self.delivery_start <= now && self.delivery_finish >= now))
        end
      Severity: Minor
      Found in plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb and 1 other location - About 20 mins to fix
      plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb on lines 202..205

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

      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