fernandokosh/redmine_time_tracker

View on GitHub

Showing 71 of 71 total issues

Method index has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def index
    @time_tracker = get_current_time_tracker

    @limit = 15 # limit for both lists

Severity: Minor
Found in app/controllers/tt_overview_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 index has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def index
    query_from_id
    time_logs_query

    unless User.current.allowed_to_globally?(:tt_edit_time_logs, {})
Severity: Minor
Found in app/controllers/tt_logs_list_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

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

    if operator == "="
      "( #{TimeBooking.table_name}.project_id IN (" + value.collect { |val| "'#{connection.quote_string(val)}'" }.join(",") + ") )"
    else
      "( #{TimeBooking.table_name}.project_id NOT IN (" + value.collect { |val| "'#{connection.quote_string(val)}'" }.join(",") + ") OR #{TimeBooking.table_name}.project_id IS NULL )"
Severity: Major
Found in app/models/time_booking_query.rb and 1 other location - About 1 hr to fix
app/models/time_booking_query.rb on lines 138..141

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

    if operator == "="
      "( #{Issue.table_name}.fixed_version_id IN (" + value.collect { |val| "'#{connection.quote_string(val)}'" }.join(",") + ") )"
    else
      "( #{Issue.table_name}.fixed_version_id NOT IN (" + value.collect { |val| "'#{connection.quote_string(val)}'" }.join(",") + ") OR #{Issue.table_name}.fixed_version_id IS NULL )"
Severity: Major
Found in app/models/time_booking_query.rb and 1 other location - About 1 hr to fix
app/models/time_booking_query.rb on lines 116..119

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

  def delete
    time_tracker = TimeTracker.where(:id => params[:id]).first
    if User.current.id == time_tracker.user_id && User.current.allowed_to?([:tt_edit_own_time_logs], {}) || User.current.allowed_to_globally?([:tt_edit_time_logs], {}) # user could only delete his own entries, except he's admin
      time_tracker.destroy
    else
Severity: Minor
Found in app/controllers/time_trackers_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 tt_sort_link has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def tt_sort_link(sort_arg, column, caption, default_order)
    css, order = nil, default_order

    tt_sort_criteria = @sort_logs_criteria if sort_arg == :sort_logs
    tt_sort_criteria = @sort_bookings_criteria if sort_arg == :sort_bookings
Severity: Minor
Found in app/helpers/time_trackers_helper.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 span has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def span
    if op == 'is' || op == 'today'
      'day'
    elsif op == 'thisWeek' || op == 'between' && self.last_start == self.last_start.beginning_of_week && self.last_stop == self.last_stop.end_of_week
      'week'
Severity: Minor
Found in app/models/tt_date_shifter.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 initialize_available_filters has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def initialize_available_filters
    principals = []

    if project
      principals += project.principals.sort
Severity: Minor
Found in app/concerns/tt_query_concern.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

Avoid deeply nested control flow statements.
Open

          raise StandardError, l(:tt_error_not_allowed_to_change_logs) if self.user.id == User.current.id
Severity: Major
Found in app/models/time_log.rb - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

              raise StandardError, l(:tt_error_not_allowed_to_change_logs) if self.user.id == User.current.id
    Severity: Major
    Found in app/models/time_log.rb - About 45 mins to fix

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

        def create
          @query = TimeBookingQuery.new(params[:query])
          @query.user = User.current
          @query.project = params[:query_is_for_all] ? nil : @project
          @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
      Severity: Minor
      Found in app/controllers/time_booking_queries_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 create has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          @query = TimeLogQuery.new(params[:query])
          @query.user = User.current
          @query.project = params[:query_is_for_all] ? nil : @project
          @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
      Severity: Minor
      Found in app/controllers/time_log_queries_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 add_booking has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def add_booking(args = {})
          default_args = {:started_on => self.started_on, :stopped_at => self.stopped_at, :comments => self.comments, :activity_id => args[:activity_id], :issue => nil, :spent_time => nil, :project_id => self.project_id}
          args = default_args.merge(args)
      
          # TODO check time boundaries
      Severity: Minor
      Found in app/models/time_log.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

      Avoid deeply nested control flow statements.
      Open

                raise StandardError, l(:tt_error_not_allowed_to_change_logs) if self.user.id == User.current.id
      Severity: Major
      Found in app/models/time_tracker.rb - About 45 mins to fix

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

          def visible?(user=User.current)
            return true if user.admin?
            return false unless project.nil? || user.allowed_to?(@visible_permission, project)
            case visibility
              when Query::VISIBILITY_PUBLIC
        Severity: Minor
        Found in app/concerns/tt_query_concern.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

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

              map.permission :tt_edit_bookings, {:time_bookings => [:actions, :delete, :get_list_entry, :show_edit, :update],
                                                 :time_logs => [:show_booking],
                                                 :tt_bookings_list => [:index],
                                                 :tt_completer => [:get_issue, :get_issue_id, :get_issue_subject],
                                                 :tt_date_shifter => [:get_next_time_span, :get_prev_time_span],
        Severity: Minor
        Found in init.rb and 1 other location - About 45 mins to fix
        init.rb on lines 77..86

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

        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

              map.permission :tt_edit_own_bookings, {:time_bookings => [:actions, :delete, :get_list_entry, :show_edit, :update],
                                                     :time_logs => [:show_booking],
                                                     :tt_bookings_list => [:index],
                                                     :tt_completer => [:get_issue, :get_issue_id, :get_issue_subject],
                                                     :tt_date_shifter => [:get_next_time_span, :get_prev_time_span],
        Severity: Minor
        Found in init.rb and 1 other location - About 45 mins to fix
        init.rb on lines 87..97

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

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

          def update
            @query.attributes = params[:query]
            @query.project = nil if params[:query_is_for_all]
            @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
            @query.build_from_params(params)
        Severity: Minor
        Found in app/controllers/time_log_queries_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

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

          def update
            @time_tracker = get_current
            @time_tracker.update_attributes!(params[:time_tracker])
            flash[:notice] = l(:update_time_tracker_success)
            unless request.xhr?
        Severity: Minor
        Found in app/controllers/time_trackers_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

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

          def sql_for_tt_log_bookable_field(field, operator, value = ["1"])
            case operator
              when "="
                if value[0] == "1"
                  "#{TimeLog.table_name}.bookable = " + connection.quoted_true
        Severity: Minor
        Found in app/models/time_log_query.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