Codeminer42/cm42-central

View on GitHub
app/models/story.rb

Summary

Maintainability
C
7 hrs
Test Coverage

Class has too many lines. [245/110]
Open

class Story < ApplicationRecord
  include ActiveModel::Transitions
  extend Enumerize

  before_validation :set_position_to_last
Severity: Minor
Found in app/models/story.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method from_csv_row has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    def from_csv_row(row)
      # Ensure no email notifications get sent during CSV import
      project = proxy_association.owner.project
      project.suppress_notifications

Severity: Minor
Found in app/models/story.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

Class Story has 25 methods (exceeds 20 allowed). Consider refactoring.
Open

class Story < ApplicationRecord
  include ActiveModel::Transitions
  extend Enumerize

  before_validation :set_position_to_last
Severity: Minor
Found in app/models/story.rb - About 2 hrs to fix

    Cyclomatic complexity for from_csv_row is too high. [7/6]
    Open

        def from_csv_row(row)
          # Ensure no email notifications get sent during CSV import
          project = proxy_association.owner.project
          project.suppress_notifications
    
    
    Severity: Minor
    Found in app/models/story.rb by rubocop

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

    Complex method Story::has_many#from_csv_row (32.7)
    Open

        def from_csv_row(row)
          # Ensure no email notifications get sent during CSV import
          project = proxy_association.owner.project
          project.suppress_notifications
    
    
    Severity: Minor
    Found in app/models/story.rb by flog

    Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

    You can read more about ABC metrics or the flog tool

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

      def set_started_at
        return unless state_changed?
        return unless state == 'started'
        self.started_at = Time.current if started_at.nil?
        self.owned_by = acting_user if owned_by.nil? && acting_user
    Severity: Minor
    Found in app/models/story.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 column has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def column
        case state
        when 'unscheduled'
          '#chilly_bin'
        when 'unstarted'
    Severity: Minor
    Found in app/models/story.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 set_accepted_at has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def set_accepted_at
        return unless state_changed?
        return unless state == 'accepted'
        self.accepted_at = Time.current if accepted_at.nil?
        self.cycle_time = accepted_at - started_at if started_at
    Severity: Minor
    Found in app/models/story.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

    Use find_by instead of dynamic find_by_username.
    Open

                user: project.users.find_by_username(matches[2]),
    Severity: Minor
    Found in app/models/story.rb by rubocop

    This cop checks dynamic find_by_* methods. Use find_by instead of dynamic method. See. https://github.com/bbatsov/rails-style-guide#find_by

    Example:

    # bad
    User.find_by_name(name)
    
    # bad
    User.find_by_name_and_email(name)
    
    # bad
    User.find_by_email!(name)
    
    # good
    User.find_by(name: name)
    
    # good
    User.find_by(name: name, email: email)
    
    # good
    User.find_by!(email: email)

    Use %i or %I for an array of symbols.
    Open

      scope :in_progress, -> { where(state: [:started, :finished, :delivered]) }
    Severity: Minor
    Found in app/models/story.rb by rubocop

    This cop can check for array literals made up of symbols that are not using the %i() syntax.

    Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax, perhaps because they support a version of Ruby lower than 2.0.

    Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

    Example:

    EnforcedStyle: percent (default)
    
    # good
    %i[foo bar baz]
    
    # bad
    [:foo, :bar, :baz]

    Example:

    EnforcedStyle: brackets
    
    # good
    [:foo, :bar, :baz]
    
    # bad
    %i[foo bar baz]

    Indent the right bracket the same as the start of the line where the left bracket is.
    Open

        ]
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Story Type", "Estimate", "Current State", "Started At", "Created at", "Accepted at",
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Align the elements of a hash literal if they span more than one line.
    Open

                user_name: matches[2],
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Id", "Story", "Labels", "Iteration", "Iteration Start", "Iteration End",
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Use next to skip iteration.
    Open

            if %w[Note Comment].include?(header) && value
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Use next to skip iteration instead of a condition at the end.

    Example:

    # bad
    [1, 2].each do |a|
      if a == 1
        puts a
      end
    end
    
    # good
    [1, 2].each do |a|
      next unless a == 1
      puts a
    end

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Story Type", "Estimate", "Current State", "Started At", "Created at", "Accepted at",
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Align the elements of a hash literal if they span more than one line.
    Open

                user: project.users.find_by_username(matches[2]),
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Align the elements of a hash literal if they span more than one line.
    Open

                created_at: matches[3])
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Line is too long. [113/100]
    Open

            if iteration_service.current_iteration_number == iteration_service.iteration_number_for_date(accepted_at)
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Assignment in condition - you probably meant to use ==.
    Open

              next unless matches = /(.*)\((.*) - (.*)\)$/.match(value)
    Severity: Minor
    Found in app/models/story.rb by rubocop

    This cop checks for assignments in the conditions of if/while/until.

    Example:

    # bad
    
    if some_var = true
      do_something
    end

    Example:

    # good
    
    if some_var == true
      do_something
    end

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Story Type", "Estimate", "Current State", "Started At", "Created at", "Accepted at",
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Freeze mutable objects assigned to constants.
    Open

      CSV_HEADERS = [
        "Id", "Story", "Labels", "Iteration", "Iteration Start", "Iteration End",
        "Story Type", "Estimate", "Current State", "Started At", "Created at", "Accepted at",
        "Deadline", "Requested By", "Owned By", "Description", "URL"
        ]
    Severity: Minor
    Found in app/models/story.rb by rubocop

    This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

    Example:

    # bad
    CONST = [1, 2, 3]
    
    # good
    CONST = [1, 2, 3].freeze

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Id", "Story", "Labels", "Iteration", "Iteration Start", "Iteration End",
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Story Type", "Estimate", "Current State", "Started At", "Created at", "Accepted at",
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Deadline", "Requested By", "Owned By", "Description", "URL"
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Deadline", "Requested By", "Owned By", "Description", "URL"
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Deadline", "Requested By", "Owned By", "Description", "URL"
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Id", "Story", "Labels", "Iteration", "Iteration Start", "Iteration End",
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Id", "Story", "Labels", "Iteration", "Iteration Start", "Iteration End",
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Story Type", "Estimate", "Current State", "Started At", "Created at", "Accepted at",
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Id", "Story", "Labels", "Iteration", "Iteration Start", "Iteration End",
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Id", "Story", "Labels", "Iteration", "Iteration Start", "Iteration End",
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Deadline", "Requested By", "Owned By", "Description", "URL"
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Deadline", "Requested By", "Owned By", "Description", "URL"
    Severity: Minor
    Found in app/models/story.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        "Story Type", "Estimate", "Current State", "Started At", "Created at", "Accepted at",
    Severity: Minor
    Found in app/models/story.rb by rubocop

    There are no issues that match your filters.

    Category
    Status