5xRuby/daikichi

View on GitHub

Showing 19 of 19 total issues

Method build_leave_time_usages has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

  def build_leave_time_usages
    ActiveRecord::Base.transaction do
      validate_application_covered_by_leave_time_interval

      @available_leave_times.each do |lt|
Severity: Minor
Found in app/services/leave_time_usage_builder.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

Class BaseController has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

class BaseController < ApplicationController
  before_action :set_actions
  helper_method :current_collection, :current_object

  load_and_authorize_resource
Severity: Minor
Found in app/controllers/base_controller.rb - About 2 hrs to fix

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

      $leaveStatus.on('change', function(e){
        status = $(this).val();
        year = $year.val();
        Turbolinks.visit("/backend/leave_applications?status=" + status + "&year=" + year );
      })
    Severity: Major
    Found in app/assets/javascripts/pages/backend/leave_applications.js and 2 other locations - About 2 hrs to fix
    app/assets/javascripts/pages/backend/leave_applications.js on lines 13..17
    app/assets/javascripts/pages/leave_applications.js on lines 6..10

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

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

      $leaveStatus.on('change', function(e){
        status = $(this).val();
        year = $year.val();
        Turbolinks.visit("/leave_applications?status=" + status + "&year=" + year );
      })
    Severity: Major
    Found in app/assets/javascripts/pages/leave_applications.js and 2 other locations - About 2 hrs to fix
    app/assets/javascripts/pages/backend/leave_applications.js on lines 6..10
    app/assets/javascripts/pages/backend/leave_applications.js on lines 13..17

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

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

      $year.on('change', function(e){
        year = $(this).val();
        status = $leaveStatus.val();
        Turbolinks.visit("/backend/leave_applications?status=" + status + "&year=" + year );
      })
    Severity: Major
    Found in app/assets/javascripts/pages/backend/leave_applications.js and 2 other locations - About 2 hrs to fix
    app/assets/javascripts/pages/backend/leave_applications.js on lines 6..10
    app/assets/javascripts/pages/leave_applications.js on lines 6..10

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

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

      $statistics_month.on('change', function() {
        Turbolinks.visit("/backend/leave_applications/statistics?year=" + $statistics_year.val() + "&month=" + $statistics_month.val() + "&role=" + $statistics_role.val());
      });
    Severity: Major
    Found in app/assets/javascripts/pages/backend/leave_applications.js and 2 other locations - About 1 hr to fix
    app/assets/javascripts/pages/backend/leave_applications.js on lines 24..26
    app/assets/javascripts/pages/backend/leave_applications.js on lines 32..34

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

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

      $statistics_year.on('change', function() {
        Turbolinks.visit("/backend/leave_applications/statistics?year=" + $statistics_year.val() + "&month=" + $statistics_month.val() + "&role=" + $statistics_role.val());
      });
    Severity: Major
    Found in app/assets/javascripts/pages/backend/leave_applications.js and 2 other locations - About 1 hr to fix
    app/assets/javascripts/pages/backend/leave_applications.js on lines 28..30
    app/assets/javascripts/pages/backend/leave_applications.js on lines 32..34

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

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

      $statistics_role.on("change", function() {
        Turbolinks.visit("/backend/leave_applications/statistics?year=" + $statistics_year.val() + "&month=" + $statistics_month.val() + "&role=" + $statistics_role.val());
      });
    Severity: Major
    Found in app/assets/javascripts/pages/backend/leave_applications.js and 2 other locations - About 1 hr to fix
    app/assets/javascripts/pages/backend/leave_applications.js on lines 24..26
    app/assets/javascripts/pages/backend/leave_applications.js on lines 28..30

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

    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 build_monthly_leave_types has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def build_monthly_leave_types(leave_type, config, prebuild, build_by_assign_date = false)
        quota = extract_quota(config, @user, prebuild: prebuild)
        if build_by_assign_date
          date = @user.assign_date >= @user.join_date ? @user.assign_date : @user.join_date
          while date <= Time.zone.now.to_date
    Severity: Minor
    Found in app/services/leave_time_builder.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 join_date_based_by_assign_date has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

      def join_date_based_by_assign_date(leave_type, quota)
        if @user.assign_date < @user.join_date
          date = @user.join_date
          expiration_date = date.next_year - 1.day
        else
    Severity: Minor
    Found in app/services/leave_time_builder.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_application_covered_by_leave_time_interval has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

      def validate_application_covered_by_leave_time_interval
        include_start_time = include_end_time = false
        @available_leave_times.each do |lt|
          include_start_time = true if lt.cover?(@leave_hours_by_date.keys.first) # leave_time start_date 跟 date 相同會不會 cover 到
          include_end_time = true if lt.cover?(@leave_hours_by_date.keys.last)
    Severity: Minor
    Found in app/services/leave_time_usage_builder.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

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

      $year.on('change', function() {
        Turbolinks.visit("/backend/monthly_leave_times?year=" + $year.val() + "&month=" + $month.val());
      });
    Severity: Minor
    Found in app/assets/javascripts/pages/backend/monthly_leave_times.js and 1 other location - About 55 mins to fix
    app/assets/javascripts/pages/backend/monthly_leave_times.js on lines 10..12

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

    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

      $month.on('change', function() {
        Turbolinks.visit("/backend/monthly_leave_times?year=" + $year.val() + "&month=" + $month.val());
      });
    Severity: Minor
    Found in app/assets/javascripts/pages/backend/monthly_leave_times.js and 1 other location - About 55 mins to fix
    app/assets/javascripts/pages/backend/monthly_leave_times.js on lines 6..8

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

    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 get_from_duration_num has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def get_from_duration_num(duration_num)
        found_at = @ranges.index do |pair|
          (pair[0].present? ? (duration_num >= pair[0]) : true) &&
            (pair[1].present? ? (duration_num <= pair[1]) : true)
        end
    Severity: Minor
    Found in lib/duration_range_to_value.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 build_special_leave_time_usages has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def build_special_leave_time_usages
        return unless self.special_type?
        leave_applications = User.find(self.user_id).leave_applications.where(leave_type: self.leave_type)
        leave_applications.each do |la|
          if la.leave_time_usages.empty? and la.hours <= la.available_leave_times.pluck(:usable_hours).sum
    Severity: Minor
    Found in app/models/leave_time.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

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

        init: function() {
          var $this = this;
          $this.$datePickers.each(function() {
            $this.initDatePickers(this);
          });
    Severity: Minor
    Found in app/assets/javascripts/datepicker.js and 1 other location - About 40 mins to fix
    app/assets/javascripts/datetimepicker.js on lines 16..21

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

    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

        init: function() {
          var $this = this;
          $this.$dateTimePickers.each(function() {
            $this.initDateTimePickers(this);
          });
    Severity: Minor
    Found in app/assets/javascripts/datetimepicker.js and 1 other location - About 40 mins to fix
    app/assets/javascripts/datepicker.js on lines 12..17

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

    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 after_update has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def after_update(record)
        create_leave_time_usages(record) if record.aasm_event?(:revise)
        FlowdockService.new(leave_application: record).send_update_notification(record.aasm.to_state) if Rails.env.production?
        UserMailer.reply_leave_applicaiton_email(record).deliver_later if record.aasm_event?(:approve) or record.aasm_event?(:reject)
        InformationMailer.cancel_application(record).deliver_later if record.aasm_event?(:cancel) && Rails.env.production?
    Severity: Minor
    Found in app/models/leave_application_observer.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

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

      def update
        if current_object.canceled?
          action_fail t('warnings.not_cancellable'), :edit
        else
          current_object.assign_attributes(resource_params)
    Severity: Minor
    Found in app/controllers/leave_applications_controller.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

    Severity
    Category
    Status
    Source
    Language