bsc-networks/workshift-website

View on GitHub

Showing 16 of 16 total issues

Class WorkshiftAssignment has 28 methods (exceeds 20 allowed). Consider refactoring.
Open

class WorkshiftAssignment < ActiveRecord::Base
  belongs_to :workshifter, class_name: "User", foreign_key: "workshifter_id"
  belongs_to :verifier, class_name: "User", foreign_key: "verifier_id"
  belongs_to :workshift
  belongs_to :unit
Severity: Minor
Found in app/models/workshift_assignment.rb - About 3 hrs to fix

    Method best_assignment_candidates has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

      def best_assignment_candidates(unit)
        best_candidates = {
          highest_pref: [],
          most_needed_hours: []
        }
    Severity: Minor
    Found in app/models/workshift.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 best_assignment_candidates has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def best_assignment_candidates(unit)
        best_candidates = {
          highest_pref: [],
          most_needed_hours: []
        }
    Severity: Minor
    Found in app/models/workshift.rb - About 2 hrs to fix

      Method profile has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def profile
          id = params[:id] || current_user.id
          @user = User.where(unit_id: current_user.unit).find(id)
          @other_units = (Unit.all.size == 1) ? Unit.all : Unit.find(:all, :conditions => ["id != ?", @user.id])
          if not @user.unit.nil?
      Severity: Minor
      Found in app/controllers/users_controller.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 hours_multiplier has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def hours_multiplier
          return -1 if status == 'missed'
          return 1 if status == 'complete'
          if purchased?
            return -1 if status == 'blown'
      Severity: Minor
      Found in app/models/workshift_assignment.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 time_to_hour_string has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.time_to_hour_string(time)
          hour = time.hour
          if hour <= 12
            period = (hour > 10) ? "PM" : "AM"
            if (hour == 12)
      Severity: Minor
      Found in app/models/workshift.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

        def set_day_start_time(day, start_time)
          if day == 'weekdays'
            ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday'].each do |weekday|
              day_quiet_hours.where(day: weekday).update_all(:start_time => start_time)
            end
      Severity: Major
      Found in app/models/quiet_hour.rb and 1 other location - About 1 hr to fix
      app/models/quiet_hour.rb on lines 29..40

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

      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 set_day_end_time(day, end_time)
          if day == 'weekdays'
            ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'].each do |weekday|
              day_quiet_hours.where(day: weekday).update_all(:end_time => end_time)
            end
      Severity: Major
      Found in app/models/quiet_hour.rb and 1 other location - About 1 hr to fix
      app/models/quiet_hour.rb on lines 15..26

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

      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

            best_candidates[:highest_pref] = available.sort do |a, b|
              a_rank = a[2]
              b_rank = b[2]
              case
              when a_rank < b_rank
      Severity: Minor
      Found in app/models/workshift.rb and 1 other location - About 40 mins to fix
      app/models/workshift.rb on lines 175..186

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

      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

          best_candidates[:most_needed_hours] = available.sort do |a, b|
            a_hours = a[3]
            b_hours = b[3]
            case
            when a_hours < b_hours
      Severity: Minor
      Found in app/models/workshift.rb and 1 other location - About 40 mins to fix
      app/models/workshift.rb on lines 160..170

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

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

        def create
          authorize :workshift
          days = params[:workshift].delete('day')
          days.pop # remove added empty string ('') entry
          if days.length == 0
      Severity: Minor
      Found in app/controllers/workshifts_controller.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 -2 if status == 'blown'
      Severity: Major
      Found in app/models/workshift_assignment.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

              return -1 if status == 'sold'
        Severity: Major
        Found in app/models/workshift_assignment.rb - About 30 mins to fix

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

            def add_users
              authorize :user
              @user_info = params[:user_info]
              begin
                if current_user.workshift_manager? or current_user.unit_level_admin?
          Severity: Minor
          Found in app/controllers/users_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

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

            def update_workshifter_hours_balance
              case status
              when "complete"
                if purchased?
                  self.workshifter.hours_balance += self.hours
          Severity: Minor
          Found in app/models/workshift_assignment.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 invite_users_in_units has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.invite_users_in_units(user_info)
              fail ArgumentError, 'Must input at least one userattr_accessible' if user_info.length == 0
              num_invited = 0
              CSV.parse(user_info) do |row|
                fail ArgumentError, 'Improperly formatted user information on row '\
          Severity: Minor
          Found in app/models/user.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