tansaku/LocalSupport

View on GitHub
app/models/organisation.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Class has too many lines. [155/100]
Open

class Organisation < BaseOrganisation

  has_many :volunteer_ops
  has_many :users
  has_many :edits, class_name: 'ProposedOrganisationEdit', :dependent => :destroy
Severity: Minor
Found in app/models/organisation.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.

Class Organisation has 27 methods (exceeds 20 allowed). Consider refactoring.
Open

class Organisation < BaseOrganisation

  has_many :volunteer_ops
  has_many :users
  has_many :edits, class_name: 'ProposedOrganisationEdit', :dependent => :destroy
Severity: Minor
Found in app/models/organisation.rb - About 3 hrs to fix

    Method has too many lines. [11/5] (https://github.com/bbatsov/ruby-style-guide#short-methods)
    Open

      def self.import(filename, limit, validation, &block)
        csv_text = File.open(filename, 'r:ISO-8859-1')
        count = 0
        CSV.parse(csv_text, :headers => true).each do |row|
          break if count >= limit
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

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

    Method has too many lines. [7/5] (https://github.com/bbatsov/ruby-style-guide#short-methods)
    Open

      def can_add_or_invite_admin?(email)
        return false if email.blank?
        usr = User.find_by_email(email)
        return add_and_notify(usr) if usr.present?
        result = ::SingleInviteJob.new(self, email).invite_user
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

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

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

      def self.create_and_validate(attributes)
        # create!(attributes.select{|k,v| !v.nil?})
        create!(attributes.each { |k, v| attributes[k] =v.nil? ? 'No information recorded' : (v.empty? ? 'No information recorded' : v) })
      end
    Severity: Minor
    Found in app/models/organisation.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

    TODO found
    Open

      accepts_nested_attributes_for :users # TODO check if needed
    Severity: Minor
    Found in app/models/organisation.rb by fixme

    Line is too long. [113/90] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

          .having(organisation_id.count.eq category_ids.size) # and return the orgs with correct number of duplicates
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Line is too long. [116/90] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

      scope :without_matching_user_emails, lambda {where("organisations.email NOT IN (#{User.select('email').to_sql})")}
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Use the new Ruby 1.9 hash syntax. (https://github.com/bbatsov/ruby-style-guide#hash-literals)
    Open

      has_many :edits, class_name: 'ProposedOrganisationEdit', :dependent => :destroy
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    This cop checks hash literal syntax.

    It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).

    A separate offense is registered for each problematic pair.

    The supported styles are:

    • ruby19 - forces use of the 1.9 syntax (e.g. {a: 1}) when hashes have all symbols for keys
    • hash_rockets - forces use of hash rockets for all hashes
    • nomixedkeys - simply checks for hashes with mixed syntaxes
    • ruby19nomixed_keys - forces use of ruby 1.9 syntax and forbids mixed syntax hashes

    Example: EnforcedStyle: ruby19 (default)

    # bad
    {:a => 2}
    {b: 1, :c => 2}
    
    # good
    {a: 2, b: 1}
    {:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
    {d: 1, 'e' => 2} # technically not forbidden

    Example: EnforcedStyle: hash_rockets

    # bad
    {a: 1, b: 2}
    {c: 1, 'd' => 5}
    
    # good
    {:a => 1, :b => 2}

    Example: EnforcedStyle: nomixedkeys

    # bad
    {:a => 1, b: 2}
    {c: 1, 'd' => 2}
    
    # good
    {:a => 1, :b => 2}
    {c: 1, d: 2}

    Example: EnforcedStyle: ruby19nomixed_keys

    # bad
    {:a => 1, :b => 2}
    {c: 2, 'd' => 3} # should just use hash rockets
    
    # good
    {a: 1, b: 2}
    {:c => 3, 'd' => 4}

    Unused method argument - block. If it's necessary, use _ or _block as an argument name to indicate that it won't be used. (https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars)
    Open

      def self.import(filename, limit, validation, &block)
    Severity: Minor
    Found in app/models/organisation.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

    Line is too long. [93/90] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

      # Alternative => :joins('LEFT OUTER JOIN users ON users.organisation_id = organisations.id)
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Line is too long. [106/90] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

      scope :null_users, lambda { includes(:users).where("users.organisation_id IS NULL").references(:users) }
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Unused method argument - validation. If it's necessary, use _ or _validation as an argument name to indicate that it won't be used. (https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars)
    Open

      def self.add_email(row, validation)
    Severity: Minor
    Found in app/models/organisation.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

    Line is too long. [96/90] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

        create!(attributes.each { |k, v| attributes[k] = v.empty? ? 'NO INFORMATION RECORDED' : v })
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Line is too long. [95/90] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

            raise CSV::MalformedCSVError, "No expected column with name #{column_name} in CSV file"
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Ternary operators must not be nested. Prefer if or else constructs instead. (https://github.com/bbatsov/ruby-style-guide#no-nested-ternary)
    Open

        create!(attributes.each { |k, v| attributes[k] =v.nil? ? 'No information recorded' : (v.empty? ? 'No information recorded' : v) })
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Line is too long. [124/90] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

          .where(category_id.in category_ids)                 # at this point, orgs in multiple categories show up as duplicates
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Redundant return detected. (https://github.com/bbatsov/ruby-style-guide#no-explicit-return)
    Open

        return "#{row[0]} was found\n"
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    This cop checks for redundant return expressions.

    Example:

    def test
      return something
    end
    
    def test
      one
      two
      three
      return something
    end

    It should be extended to handle methods whose body is if/else or a case expression with a default branch.

    Line is too long. [122/90] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

        error_msg = ("Error: Email is invalid" == error_msg) ? "The user email you entered,'#{email}', is invalid" : error_msg
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Use the -> { ... } lambda literal syntax for single line lambdas. (https://github.com/bbatsov/ruby-style-guide#lambda-multi-line)
    Open

      scope :null_users, lambda { includes(:users).where("users.organisation_id IS NULL").references(:users) }
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.

    Example: EnforcedStyle: linecountdependent (default)

    # bad
    f = lambda { |x| x }
    f = ->(x) do
          x
        end
    
    # good
    f = ->(x) { x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: lambda

    # bad
    f = ->(x) { x }
    f = ->(x) do
          x
        end
    
    # good
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: literal

    # bad
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end
    
    # good
    f = ->(x) { x }
    f = ->(x) do
          x
        end

    Use the -> { ... } lambda literal syntax for single line lambdas. (https://github.com/bbatsov/ruby-style-guide#lambda-multi-line)
    Open

      scope :without_matching_user_emails, lambda {where("organisations.email NOT IN (#{User.select('email').to_sql})")}
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.

    Example: EnforcedStyle: linecountdependent (default)

    # bad
    f = lambda { |x| x }
    f = ->(x) do
          x
        end
    
    # good
    f = ->(x) { x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: lambda

    # bad
    f = ->(x) { x }
    f = ->(x) do
          x
        end
    
    # good
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: literal

    # bad
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end
    
    # good
    f = ->(x) { x }
    f = ->(x) do
          x
        end

    Prefer single-quoted strings when you don't need string interpolation or special symbols. (https://github.com/bbatsov/ruby-style-guide#consistent-string-literals)
    Open

        error_msg = ("Error: Email is invalid" == error_msg) ? "The user email you entered,'#{email}', is invalid" : error_msg
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Use the new Ruby 1.9 hash syntax. (https://github.com/bbatsov/ruby-style-guide#hash-literals)
    Open

        CSV.parse(csv_text, :headers => true).each do |row|
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    This cop checks hash literal syntax.

    It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).

    A separate offense is registered for each problematic pair.

    The supported styles are:

    • ruby19 - forces use of the 1.9 syntax (e.g. {a: 1}) when hashes have all symbols for keys
    • hash_rockets - forces use of hash rockets for all hashes
    • nomixedkeys - simply checks for hashes with mixed syntaxes
    • ruby19nomixed_keys - forces use of ruby 1.9 syntax and forbids mixed syntax hashes

    Example: EnforcedStyle: ruby19 (default)

    # bad
    {:a => 2}
    {b: 1, :c => 2}
    
    # good
    {a: 2, b: 1}
    {:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
    {d: 1, 'e' => 2} # technically not forbidden

    Example: EnforcedStyle: hash_rockets

    # bad
    {a: 1, b: 2}
    {c: 1, 'd' => 5}
    
    # good
    {:a => 1, :b => 2}

    Example: EnforcedStyle: nomixedkeys

    # bad
    {:a => 1, b: 2}
    {c: 1, 'd' => 2}
    
    # good
    {:a => 1, :b => 2}
    {c: 1, d: 2}

    Example: EnforcedStyle: ruby19nomixed_keys

    # bad
    {:a => 1, :b => 2}
    {c: 2, 'd' => 3} # should just use hash rockets
    
    # good
    {a: 1, b: 2}
    {:c => 3, 'd' => 4}

    Prefer single-quoted strings when you don't need string interpolation or special symbols. (https://github.com/bbatsov/ruby-style-guide#consistent-string-literals)
    Open

      scope :null_users, lambda { includes(:users).where("users.organisation_id IS NULL").references(:users) }
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Prefer single-quoted strings when you don't need string interpolation or special symbols. (https://github.com/bbatsov/ruby-style-guide#consistent-string-literals)
    Open

        orgs = where("UPPER(name) LIKE ? ","%#{row[0].try(:upcase)}%")
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Replace class var @@column_mappings with a class instance var. (https://github.com/bbatsov/ruby-style-guide#no-class-vars)
    Open

      @@column_mappings = {
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

    Unused block argument - validation. If it's necessary, use _ or _validation as an argument name to indicate that it won't be used. (https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars)
    Open

        import(filename, limit, false) do |row, validation|
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    This cop checks for unused block arguments.

    Example:

    # bad
    
    do_something do |used, unused|
      puts used
    end
    
    do_something do |bar|
      puts :foo
    end
    
    define_method(:foo) do |bar|
      puts :baz
    end

    Example:

    #good
    
    do_something do |used, _unused|
      puts used
    end
    
    do_something do
      puts :foo
    end
    
    define_method(:foo) do |_bar|
      puts :baz
    end

    Line is too long. [134/90] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

        create!(attributes.each { |k, v| attributes[k] =v.nil? ? 'No information recorded' : (v.empty? ? 'No information recorded' : v) })
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    Use the -> { ... } lambda literal syntax for single line lambdas. (https://github.com/bbatsov/ruby-style-guide#lambda-multi-line)
    Open

      scope :not_null_email, lambda {where("organisations.email <> ''")}
    Severity: Minor
    Found in app/models/organisation.rb by rubocop

    This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.

    Example: EnforcedStyle: linecountdependent (default)

    # bad
    f = lambda { |x| x }
    f = ->(x) do
          x
        end
    
    # good
    f = ->(x) { x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: lambda

    # bad
    f = ->(x) { x }
    f = ->(x) do
          x
        end
    
    # good
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: literal

    # bad
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end
    
    # good
    f = ->(x) { x }
    f = ->(x) do
          x
        end

    There are no issues that match your filters.

    Category
    Status