ari/jobsworth

View on GitHub
app/models/worklog_report.rb

Summary

Maintainability
F
1 wk
Test Coverage

File worklog_report.rb has 468 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class WorklogReport
  include ERB::Util

  PIVOT = 1
  AUDIT = 2
Severity: Minor
Found in app/models/worklog_report.rb - About 7 hrs to fix

    Method init_rows_and_columns has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

      def init_rows_and_columns
        @total = 0
        @row_totals = {}
        @column_totals = {}
        @column_headers = {}
    Severity: Minor
    Found in app/models/worklog_report.rb - 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 create_csv has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

      def create_csv
        csv_string = ''
        if @column_headers
          CSV.generate(csv_string, :col_sep => ',') do |csv|
    
    
    Severity: Minor
    Found in app/models/worklog_report.rb - 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 key_from_worklog has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

      def key_from_worklog(w, r)
        if r == 1
          "#{w.customer.name} #{w.project.name} #{w.task.name} #{w.task.task_num}"
        elsif r == 2
          w.is_a?(Tag) ? w.id : 0
    Severity: Minor
    Found in app/models/worklog_report.rb - About 4 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 name_from_worklog has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

      def name_from_worklog(w, r)
        if r == 1
          "#{w.task.issue_num} <a href=\"/tasks/view/#{w.task.task_num}\">#{ERB::Util.h w.task.name}</a> <br /><small>#{ERB::Util.h w.task.full_name}</small>".html_safe
        elsif r == 2
          w.is_a?(Tag) ? "#{w.name}" : I18n.t('worklog_reports.status.none')
    Severity: Minor
    Found in app/models/worklog_report.rb - About 4 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 do_column has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

      def do_column(w, key)
        @column_totals[key] += w.duration unless ['comment', '1_start', '2_end', '3_task', '4_note'].include?(key)
    
        rkey = key_from_worklog(w, 15).to_s
        row_name = name_from_worklog(w, 1)
    Severity: Minor
    Found in app/models/worklog_report.rb - About 4 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 do_row has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

      def do_row(rkey, rname, vkey, duration)
        unless @rows[rkey]
          @rows[rkey] ||= {}
          @row_totals[rkey] ||= 0
          @rows[rkey]['__'] = rname
    Severity: Minor
    Found in app/models/worklog_report.rb - About 2 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 init_rows_and_columns has 52 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def init_rows_and_columns
        @total = 0
        @row_totals = {}
        @column_totals = {}
        @column_headers = {}
    Severity: Major
    Found in app/models/worklog_report.rb - About 2 hrs to fix

      Method do_column has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def do_column(w, key)
          @column_totals[key] += w.duration unless ['comment', '1_start', '2_end', '3_task', '4_note'].include?(key)
      
          rkey = key_from_worklog(w, 15).to_s
          row_name = name_from_worklog(w, 1)
      Severity: Minor
      Found in app/models/worklog_report.rb - About 1 hr to fix

        Method key_from_worklog has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def key_from_worklog(w, r)
            if r == 1
              "#{w.customer.name} #{w.project.name} #{w.task.name} #{w.task.task_num}"
            elsif r == 2
              w.is_a?(Tag) ? w.id : 0
        Severity: Minor
        Found in app/models/worklog_report.rb - About 1 hr to fix

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

            def range
              return @range if @range
          
              # Swap to an appropriate range based on entries returned
              start_date = self.start_date
          Severity: Minor
          Found in app/models/worklog_report.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 init_start_and_end_dates has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            def init_start_and_end_dates(params)
              range = params[:range].to_i
              case range
                when 0
                  # Today
          Severity: Minor
          Found in app/models/worklog_report.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 name_from_worklog has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def name_from_worklog(w, r)
              if r == 1
                "#{w.task.issue_num} <a href=\"/tasks/view/#{w.task.task_num}\">#{ERB::Util.h w.task.name}</a> <br /><small>#{ERB::Util.h w.task.full_name}</small>".html_safe
              elsif r == 2
                w.is_a?(Tag) ? "#{w.name}" : I18n.t('worklog_reports.status.none')
          Severity: Minor
          Found in app/models/worklog_report.rb - About 1 hr to fix

            Method init_start_and_end_dates has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def init_start_and_end_dates(params)
                range = params[:range].to_i
                case range
                  when 0
                    # Today
            Severity: Minor
            Found in app/models/worklog_report.rb - About 1 hr to fix

              Method create_csv has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def create_csv
                  csv_string = ''
                  if @column_headers
                    CSV.generate(csv_string, :col_sep => ',') do |csv|
              
              
              Severity: Minor
              Found in app/models/worklog_report.rb - About 1 hr to fix

                Method get_days_of_week_header has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                  def get_days_of_week_header(w)
                    if [0, 1, 2].include? @range.to_i
                      I18n.l(tz.utc_to_local(w.started_at), format: '%a <br/>%d/%m').html_safe
                    elsif [3, 4].include? @range.to_i
                      if tz.utc_to_local(w.started_at).beginning_of_week.month != tz.utc_to_local(w.started_at).beginning_of_week.since(6.days).month
                Severity: Minor
                Found in app/models/worklog_report.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 init_work_logs has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                  def init_work_logs(tasks, params)
                    logs = []
                
                    ids = tasks.collect { |t| t.id }
                    logs = WorkLog.level_accessed_by(current_user).where('task_id in (?)', ids).includes(:project, :_user_, :customer, :company => [:custom_attributes], :task => [:tags, :milestone])
                Severity: Minor
                Found in app/models/worklog_report.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

                Avoid deeply nested control flow statements.
                Open

                        body += "<option value='2' #{selected='selected' if w.rejected? } >#{I18n.t('work_logs.status.rejected')}</option>"
                Severity: Major
                Found in app/models/worklog_report.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                          body += "<option value='1' #{selected='selected' if w.approved? } >#{I18n.t('work_logs.status.approved')}</option>"
                  Severity: Major
                  Found in app/models/worklog_report.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                            body += "<option value='0' #{selected='selected' if w.status.to_i.zero? } >--</option>"
                    Severity: Major
                    Found in app/models/worklog_report.rb - About 45 mins to fix

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

                        def initialize(controller, params)
                          tasks = []
                          if params[:filter_project].to_i > 0
                            tasks = Project.find(params[:filter_project]).tasks
                          else
                      Severity: Minor
                      Found in app/models/worklog_report.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

                                (I18n.t('shared.week') + "#{tz.utc_to_local(w.started_at).strftime('%W').to_i + 1} <br/>" +
                                    I18n.l(tz.utc_to_local(w.started_at).beginning_of_month, format: '%d/%m') + ' - ' +
                                    I18n.l(tz.utc_to_local(w.started_at).beginning_of_week.since(6.days), format: '%d/%m')
                      Severity: Minor
                      Found in app/models/worklog_report.rb and 1 other location - About 55 mins to fix
                      app/models/worklog_report.rb on lines 480..482

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

                      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

                              (I18n.t('shared.week') + "#{tz.utc_to_local(w.started_at).strftime('%W').to_i + 1} <br/>" +
                                  I18n.l(tz.utc_to_local(w.started_at).beginning_of_week, format: '%d/%m') + ' - ' +
                                  I18n.l(tz.utc_to_local(w.started_at).beginning_of_week.since(6.days), format: '%d/%m')
                      Severity: Minor
                      Found in app/models/worklog_report.rb and 1 other location - About 55 mins to fix
                      app/models/worklog_report.rb on lines 474..476

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

                      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

                            "#{w.task.issue_num} <a href=\"/tasks/view/#{w.task.task_num}\">#{ERB::Util.h w.task.name}</a> <br /><small>#{ERB::Util.h w.task.full_name}</small>".html_safe
                      Severity: Minor
                      Found in app/models/worklog_report.rb and 1 other location - About 20 mins to fix
                      app/models/worklog_report.rb on lines 425..425

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

                      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

                            do_row(rkey, row_name, key, "#{w.task.issue_num} <a href=\"/tasks/view/#{w.task.task_num}\">#{ERB::Util.h w.task.name}</a> <br/><small>#{ERB::Util.h w.task.full_name}</small>".html_safe)
                      Severity: Minor
                      Found in app/models/worklog_report.rb and 1 other location - About 20 mins to fix
                      app/models/worklog_report.rb on lines 337..337

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

                      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