zammad/zammad

View on GitHub
app/models/calendar.rb

Summary

Maintainability
D
2 days
Test Coverage

Method fetch_parse has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

  def self.fetch_parse(location)
    if location.match?(%r{^http}i)
      result = UserAgent.get(location)
      if !result.success?
        raise result.error
Severity: Minor
Found in app/models/calendar.rb - 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 sync has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

  def sync(without_save = nil)
    return if !ical_url

    # only sync every 5 days
    if id
Severity: Minor
Found in app/models/calendar.rb - 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

File calendar.rb has 298 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Calendar < ApplicationModel
  include ChecksClientNotification
  include CanUniqName
  include HasEscalationCalculationImpact

Severity: Minor
Found in app/models/calendar.rb - About 3 hrs to fix

    Method sync has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def sync(without_save = nil)
        return if !ical_url
    
        # only sync every 5 days
        if id
    Severity: Minor
    Found in app/models/calendar.rb - About 1 hr to fix

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

        def self.fetch_parse(location)
          if location.match?(%r{^http}i)
            result = UserAgent.get(location)
            if !result.success?
              raise result.error
      Severity: Minor
      Found in app/models/calendar.rb - About 1 hr to fix

        Method business_hours_to_hash has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          def business_hours_to_hash
            business_hours
              .filter { |_, value| value[:active] && value[:timeframes] }
              .each_with_object({}) do |(day, meta), days_memo|
                days_memo[day.to_sym] = meta[:timeframes]
        Severity: Minor
        Found in app/models/calendar.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 public_holidays_to_array has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def public_holidays_to_array
            holidays = []
            public_holidays&.each do |day, meta|
              next if !meta
              next if !meta['active']
        Severity: Minor
        Found in app/models/calendar.rb - 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

        Method init_setup has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.init_setup(ip = nil)
        
            # ignore client ip if not public ip
            if ip && ip =~ %r{^(::1|127\.|10\.|172\.1[6-9]\.|172\.2[0-9]\.|172\.3[0-1]\.|192\.168\.)}
              ip = nil
        Severity: Minor
        Found in app/models/calendar.rb - About 45 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

        Method sync_default has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def sync_default
            return true if !default
        
            Calendar.find_each do |calendar|
              next if calendar.id == id
        Severity: Minor
        Found in app/models/calendar.rb - 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

        Avoid too many return statements within this method.
        Open

              return calendar
        Severity: Major
        Found in app/models/calendar.rb - About 30 mins to fix

          Method ensure_public_holidays_details has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def ensure_public_holidays_details
          
              # fillup feed info
              before = public_holidays_was
              public_holidays.each do |day, meta|
          Severity: Minor
          Found in app/models/calendar.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

          There are no issues that match your filters.

          Category
          Status