YaleSTC/shifts

View on GitHub
app/controllers/application_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

File application_controller.rb has 354 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class ApplicationController < ActionController::Base
  # almost everything we do is restricted to a department so we always load_department
  # feel free to skip_before_filter when desired
  before_filter :load_app_config
  before_filter :department_chooser
Severity: Minor
Found in app/controllers/application_controller.rb - About 4 hrs to fix

    Class ApplicationController has 32 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class ApplicationController < ActionController::Base
      # almost everything we do is restricted to a department so we always load_department
      # feel free to skip_before_filter when desired
      before_filter :load_app_config
      before_filter :department_chooser
    Severity: Minor
    Found in app/controllers/application_controller.rb - About 4 hrs to fix

      Method parse_date_and_time_output has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        def parse_date_and_time_output(form_output)
              time_attribute_names = ["start", "end", "mandatory_start", "mandatory_end"]
          time_attribute_names.each do |field_name|
      
            unless form_output["#{field_name}_time(5i)"].blank? || form_output["#{field_name}_time(4i)"].blank?
      Severity: Minor
      Found in app/controllers/application_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 parse_date_and_time_output has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def parse_date_and_time_output(form_output)
              time_attribute_names = ["start", "end", "mandatory_start", "mandatory_end"]
          time_attribute_names.each do |field_name|
      
            unless form_output["#{field_name}_time(5i)"].blank? || form_output["#{field_name}_time(4i)"].blank?
      Severity: Minor
      Found in app/controllers/application_controller.rb - About 1 hr to fix

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

          def set_payform_item_hours(model_name)
            if params[:calculate_hours] == 'user_input'
              params[model_name.to_sym][:hours] = params[:other][:hours].to_f + params[:other][:minutes].to_f/60
            else
              start_params = []
        Severity: Minor
        Found in app/controllers/application_controller.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 department_chooser has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def department_chooser
            if (params[:su_mode] && current_user.superuser?)
              current_user.update_attribute(:supermode, params[:su_mode]=='ON')
              flash[:notice] = "Supermode is now #{current_user.supermode? ? 'ON' : 'OFF'}"
              redirect_to :back
        Severity: Minor
        Found in app/controllers/application_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

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

          def user_is_owner_of(thing)
            unless current_user.is_owner_of?(thing)
              error_message = "You are not the owner of this #{thing.class.name.decamelize}."
              respond_to do |format|
                format.html do
        Severity: Major
        Found in app/controllers/application_controller.rb and 1 other location - About 1 hr to fix
        app/controllers/application_controller.rb on lines 181..198

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

        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 user_is_admin_of(thing)
            unless current_user.is_admin_of?(thing)
              error_message = "You are not authorized to administer this #{thing.class.name.decamelize}."
              respond_to do |format|
                format.html do
        Severity: Major
        Found in app/controllers/application_controller.rb and 1 other location - About 1 hr to fix
        app/controllers/application_controller.rb on lines 204..221

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

        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

              error_message = "That action is restricted to location group administrators."
              respond_to do |format|
                format.html do
                  flash[:error] = error_message
                  redirect_to access_denied_path
        Severity: Minor
        Found in app/controllers/application_controller.rb and 2 other locations - About 30 mins to fix
        app/controllers/application_controller.rb on lines 106..117
        app/controllers/application_controller.rb on lines 146..157

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

        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

              error_message = "That action is restricted to location group administrators."
              respond_to do |format|
                format.html do
                  flash[:error] = error_message
                  redirect_to access_denied_path
        Severity: Minor
        Found in app/controllers/application_controller.rb and 2 other locations - About 30 mins to fix
        app/controllers/application_controller.rb on lines 126..137
        app/controllers/application_controller.rb on lines 146..157

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

        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

              error_message = "That action is only available to superusers."
              respond_to do |format|
                format.html do
                  flash[:error] = error_message
                  redirect_to access_denied_path
        Severity: Minor
        Found in app/controllers/application_controller.rb and 2 other locations - About 30 mins to fix
        app/controllers/application_controller.rb on lines 106..117
        app/controllers/application_controller.rb on lines 126..137

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

        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