ece517-p3/expertiza

View on GitHub
app/models/question.rb

Summary

Maintainability
A
2 hrs
Test Coverage

Mass assignment is not restricted using attr_accessible
Open

class Question < ActiveRecord::Base
Severity: Critical
Found in app/models/question.rb by brakeman

This warning comes up if a model does not limit what attributes can be set through mass assignment.

In particular, this check looks for attr_accessible inside model definitions. If it is not found, this warning will be issued.

Brakeman also warns on use of attr_protected - especially since it was found to be vulnerable to bypass. Warnings for mass assignment on models using attr_protected will be reported, but at a lower confidence level.

Note that disabling mass assignment globally will suppress these warnings.

Assignment Branch Condition size for import is too high. [43.23/15]
Open

  def self.import(row, _row_header, session, _id = nil)
    if row.length != 5
      raise ArgumentError, "Not enough items: expect 3 columns: your login name, your full name (first and last name, not seperated with the delimiter), and your email."
    end
    questionnaire = Questionnaire.find_by_id(_id)
Severity: Minor
Found in app/models/question.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method import has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.import(row, _row_header, session, _id = nil)
    if row.length != 5
      raise ArgumentError, "Not enough items: expect 3 columns: your login name, your full name (first and last name, not seperated with the delimiter), and your email."
    end
    questionnaire = Questionnaire.find_by_id(_id)
Severity: Minor
Found in app/models/question.rb - About 1 hr to fix

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

      def self.import(row, _row_header, session, _id = nil)
        if row.length != 5
          raise ArgumentError, "Not enough items: expect 3 columns: your login name, your full name (first and last name, not seperated with the delimiter), and your email."
        end
        questionnaire = Questionnaire.find_by_id(_id)
    Severity: Minor
    Found in app/models/question.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

    Use find_by instead of dynamic find_by_id.
    Open

        questionnaire = Questionnaire.find_by_id(_id)
    Severity: Minor
    Found in app/models/question.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 find_by instead of dynamic find_by_id.
    Open

          question = Question.find_by_id(qid)
    Severity: Minor
    Found in app/models/question.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)

    Specify a :dependent option.
    Open

      has_many :signup_choices # ?? this may reference signup type questionnaires
    Severity: Minor
    Found in app/models/question.rb by rubocop

    This cop looks for has_many or has_one associations that don't specify a :dependent option. It doesn't register an offense if :through option was specified.

    Example:

    # bad
    class User < ActiveRecord::Base
      has_many :comments
      has_one :avatar
    end
    
    # good
    class User < ActiveRecord::Base
      has_many :comments, dependent: :restrict_with_exception
      has_one :avatar, dependent: :destroy
      has_many :patients, through: :appointments
    end

    Do not use prefix _ for a variable that is used.
    Open

      def self.import(row, _row_header, session, _id = nil)
    Severity: Minor
    Found in app/models/question.rb by rubocop

    This cop checks for underscore-prefixed variables that are actually used.

    Example:

    # bad
    
    [1, 2, 3].each do |_num|
      do_something(_num)
    end

    Example:

    # good
    
    [1, 2, 3].each do |num|
      do_something(num)
    end

    Example:

    # good
    
    [1, 2, 3].each do |_num|
      do_something # not using `_num`
    end

    Use a guard clause instead of wrapping the code inside a conditional expression.
    Open

        if questionnaire.nil?
    Severity: Minor
    Found in app/models/question.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok

    Surrounding space missing for operator =.
    Open

          question.questionnaire_id=_id
    Severity: Minor
    Found in app/models/question.rb by rubocop

    Checks that operators have space around them, except for ** which should not have surrounding space.

    Example:

    # bad
    total = 3*4
    "apple"+"juice"
    my_number = 38/4
    a ** b
    
    # good
    total = 3 * 4
    "apple" + "juice"
    my_number = 38 / 4
    a**b

    Do not prefix reader method names with get_.
    Open

      def get_formatted_question_type
    Severity: Minor
    Found in app/models/question.rb by rubocop

    This cop makes sure that accessor methods are named properly.

    Example:

    # bad
    def set_attribute(value)
    end
    
    # good
    def attribute=(value)
    end
    
    # bad
    def get_attribute
    end
    
    # good
    def attribute
    end

    Use a guard clause instead of wrapping the code inside a conditional expression.
    Open

        if type == 'TrueFalse'
    Severity: Minor
    Found in app/models/question.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok

    Missing space after #.
    Open

          #attributes["break_before"] = row[4].strip
    Severity: Minor
    Found in app/models/question.rb by rubocop

    This cop checks whether comments have a leading space after the # denoting the start of the comment. The leading space is not required for some RDoc special syntax, like #++, #--, #:nodoc, =begin- and =end comments, "shebang" directives, or rackup options.

    Example:

    # bad
    #Some comment
    
    # good
    # Some comment

    Line is too long. [169/160]
    Open

          raise ArgumentError, "Not enough items: expect 3 columns: your login name, your full name (first and last name, not seperated with the delimiter), and your email."
    Severity: Minor
    Found in app/models/question.rb by rubocop

    Surrounding space missing for operator =.
    Open

          question.questionnaire_id=_id
    Severity: Minor
    Found in app/models/question.rb by rubocop

    Checks that operators have space around them, except for ** which should not have surrounding space.

    Example:

    # bad
    total = 3*4
    "apple"+"juice"
    my_number = 38/4
    a ** b
    
    # good
    total = 3 * 4
    "apple" + "juice"
    my_number = 38 / 4
    a**b

    Unused method argument - session. If it's necessary, use _ or _session as an argument name to indicate that it won't be used.
    Open

      def self.import(row, _row_header, session, _id = nil)
    Severity: Minor
    Found in app/models/question.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end

    Example:

    # good
    
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    Prefer each over for.
    Open

        for q in questions
    Severity: Minor
    Found in app/models/question.rb by rubocop

    This cop looks for uses of the for keyword, or each method. The preferred alternative is set in the EnforcedStyle configuration parameter. An each call with a block on a single line is always allowed, however.

    There are no issues that match your filters.

    Category
    Status