Showing 19 of 19 total issues

Method todays_stats has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  def self.todays_stats(user)
    stats = JobStat.minutely_today(user).order(created_at: :asc)
    total_jobs_array = stats.collect { |stat| stat.total_jobs || 0 }
    enabled_jobs_array = stats.collect { |stat| stat.total_enabled || 0 }
    run_jobs_array = stats.collect { |stat| stat.runs || 0 }
Severity: Minor
Found in app/models/job_stat.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 find_jobs has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

  def self.find_jobs(user, occur_start, occur_end, tags, incexc, enabled, succeeded, running, name, timezone, command)
    search = Job.mine(user)
    search = search.enabled(enabled) unless enabled.nil?
    search = search.running(running) unless running.nil?
    search = search.successful(succeeded) unless succeeded.nil?
Severity: Minor
Found in app/models/job.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 update has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

  def update
    @job.name = params[:name] unless (@job.name == params[:name]) || params[:name].blank?
    @job.cron = params[:cron] unless (@job.cron == params[:cron]) || params[:cron].blank?
    @job.command = params[:command] unless (@job.command == params[:command]) || params[:command].blank?
    @job.timezone = params[:timezone] unless (@job.timezone == params[:timezone]) || params[:timezone].blank?
Severity: Minor
Found in app/controllers/job_api_controller.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 search_jobs has 55 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.search_jobs(user, expression)
    tags = nil
    enabled = nil
    succeeded = nil
    running = nil
Severity: Major
Found in app/models/job.rb - About 2 hrs to fix

    Method todays_stats has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.todays_stats(user)
        stats = JobStat.minutely_today(user).order(created_at: :asc)
        total_jobs_array = stats.collect { |stat| stat.total_jobs || 0 }
        enabled_jobs_array = stats.collect { |stat| stat.total_enabled || 0 }
        run_jobs_array = stats.collect { |stat| stat.runs || 0 }
    Severity: Minor
    Found in app/models/job_stat.rb - About 1 hr to fix

      Method find_jobs has 11 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        def self.find_jobs(user, occur_start, occur_end, tags, incexc, enabled, succeeded, running, name, timezone, command)
      Severity: Major
      Found in app/models/job.rb - About 1 hr to fix

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

          def self.search_jobs(user, expression)
            tags = nil
            enabled = nil
            succeeded = nil
            running = nil
        Severity: Minor
        Found in app/models/job.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 filter_runs has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          def filter_runs(start_dt, end_dt, success)
            start_dt = Chronic.parse(start_dt) unless start_dt.blank?
            end_dt = Chronic.parse(end_dt) unless end_dt.blank?
        
            query = job_runs
        Severity: Minor
        Found in app/models/job.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 update has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def update
            @folder.name = params[:name] unless (@folder.name == params[:name]) || params[:name].blank?
            @folder.expression = params[:expression] unless (@folder.expression == params[:expression]) || params[:expression].blank?
            @folder.save!
            message I18n.t('folders.messages.updated', id: @folder.id), :ok, false, @folder, 'folder'
        Severity: Minor
        Found in app/controllers/folder_api_controller.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 stop_job has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def stop_job(run, return_code, success, error_message, stdout, stderr)
        Severity: Minor
        Found in app/models/job.rb - About 45 mins to fix

          Method message has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            def message(message, status, is_error = false, object = {}, object_type = '')
          Severity: Minor
          Found in app/controllers/application_controller.rb - About 35 mins to fix

            Method iterate_over_ranges has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              def iterate_over_ranges(user, period, stat_start_dt, time_incr, end_dt)
            Severity: Minor
            Found in app/jobs/base_stats_job.rb - About 35 mins to fix

              Method update_run has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                def update_run(return_code, success, error_message, stdout, stderr)
              Severity: Minor
              Found in app/models/job_run.rb - About 35 mins to fix

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

                  def hourly_job_stats
                    stats = paginate JobStat.mine(current_user).where(period: :hour, start_dt: (@start_date || DateTime.now - 24.hours)..(@end_date || DateTime.now)).order(created_at: :asc)
                    message I18n.t('jobserver.messages.hourly_job_stats.received'), :ok, false, stats, 'jobstats'
                Severity: Major
                Found in app/controllers/job_server_api_controller.rb and 3 other locations - About 35 mins to fix
                app/controllers/job_server_api_controller.rb on lines 36..38
                app/controllers/job_server_api_controller.rb on lines 52..54
                app/controllers/job_server_api_controller.rb on lines 60..62

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

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

                  def daily_job_stats
                    stats = paginate JobStat.mine(current_user).where(period: :day, start_dt: (@start_date || DateTime.now - 7.days)..(@end_date || DateTime.now)).order(created_at: :asc)
                    message I18n.t('jobserver.messages.daily_job_stats.received'), :ok, false, stats, 'jobstats'
                Severity: Major
                Found in app/controllers/job_server_api_controller.rb and 3 other locations - About 35 mins to fix
                app/controllers/job_server_api_controller.rb on lines 36..38
                app/controllers/job_server_api_controller.rb on lines 44..46
                app/controllers/job_server_api_controller.rb on lines 60..62

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

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

                  def minutely_job_stats
                    stats = paginate JobStat.mine(current_user).where(period: :minute, start_dt: (@start_date || DateTime.now - 1.hour)..(@end_date || DateTime.now)).order(created_at: :asc)
                    message I18n.t('jobserver.messages.minutely_job_stats.received'), :ok, false, stats, 'jobstats'
                Severity: Major
                Found in app/controllers/job_server_api_controller.rb and 3 other locations - About 35 mins to fix
                app/controllers/job_server_api_controller.rb on lines 44..46
                app/controllers/job_server_api_controller.rb on lines 52..54
                app/controllers/job_server_api_controller.rb on lines 60..62

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

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

                  def weekly_job_stats
                    stats = paginate JobStat.mine(current_user).where(period: :week, start_dt: (@start_date || DateTime.now - 4.weeks)..(@end_date || DateTime.now)).order(created_at: :asc)
                    message I18n.t('jobserver.messages.weekly_job_stats.received'), :ok, false, stats, 'jobstats'
                Severity: Major
                Found in app/controllers/job_server_api_controller.rb and 3 other locations - About 35 mins to fix
                app/controllers/job_server_api_controller.rb on lines 36..38
                app/controllers/job_server_api_controller.rb on lines 44..46
                app/controllers/job_server_api_controller.rb on lines 52..54

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

                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

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

                  def update_run(return_code, success, error_message, stdout, stderr)
                    self.success = success
                    self.return_code = return_code
                    self.error_message = error_message
                    self.stdout = stdout.nil? ? '' : stdout.encode('UTF-8', invalid: :replace, undef: :replace)
                Severity: Minor
                Found in app/models/job_run.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

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

                  def compute_run_stats
                    job_runtimes = JobRun.job_runtimes(id)
                
                    avg_runtime = JobRun.avg_runtime_for_job(id)
                    max_runtime = JobRun.max_runtime_for_job(id)
                Severity: Minor
                Found in app/models/job.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

                Severity
                Category
                Status
                Source
                Language