foodcoops/foodsoft

View on GitHub

Showing 134 of 182 total issues

Method mail has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def mail(args)
    args[:message_id] ||= "<#{Mail.random_tag}@#{default_url_options[:host]}>"
    args[:subject] = "[#{FoodsoftConfig[:name]}] #{args[:subject]}"

    if args[:from].is_a? User
Severity: Minor
Found in app/mailers/mailer.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 received has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def received(data)
    mail = Mail.new data

    mail_part = get_mail_part(mail)
    raise 'No valid content could be found' if mail_part.nil?
Severity: Minor
Found in plugins/messages/app/mail_receivers/messages_mail_receiver.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 navigation has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def navigation(primary, context)
      return unless FoodsoftMessages.enabled?

      unless primary[:foodcoop].nil?
        sub_nav = primary[:foodcoop].sub_navigation
Severity: Minor
Found in plugins/messages/lib/foodsoft_messages/engine.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 group_id= has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def group_id=(group_id)
    group = Group.find(group_id) if group_id.present?
    if group
      @send_method = 'workgroup' if group.type == 'Workgroup'
      @send_method = 'ordergroup' if group.type == 'Ordergroup'
Severity: Minor
Found in plugins/messages/app/models/message.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 accept_invitation has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def accept_invitation
    @invite = Invite.find_by_token(params[:token])
    if @invite.nil? || @invite.expires_at < Time.now
      redirect_to login_url, alert: I18n.t('login.controller.error_invite_invalid')
    elsif @invite.group.nil?
Severity: Minor
Found in app/controllers/login_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 authenticate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def authenticate(role = 'any')
    # Attempt to retrieve authenticated user from controller instance or session...
    if current_user
      # We have an authenticated user, now check role...
      # Roles gets the user through his memberships.
Severity: Minor
Found in app/controllers/concerns/auth.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 get_mail_part has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def get_mail_part(mail)
    return mail unless mail.multipart?

    mail_part = nil
    for part in mail.parts
Severity: Minor
Found in plugins/messages/app/mail_receivers/messages_mail_receiver.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

          case type
          when :groups
            total += goa.result * goa.order_article.price.fc_price
          when :groups_without_markup
            total += goa.result * goa.order_article.price.gross_price
Severity: Major
Found in app/models/order.rb - About 45 mins to fix

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

      def index
        sort = if params['sort']
                 case params['sort']
                 when 'date' then 'created_on'
                 when 'note'   then 'note'
    Severity: Minor
    Found in app/controllers/finance/financial_transactions_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 []= has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def []=(key, value)
          return false unless allowed_key?(key)
    
          value = normalize_value value
          # then update database
    Severity: Minor
    Found in app/lib/foodsoft_config.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 close! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def close!(user, transaction_type = nil, financial_link = nil, create_foodcoop_transaction: false)
        raise I18n.t('orders.model.error_closed') if closed?
    
        update_price_of_group_orders!
    
    
    Severity: Minor
    Found in app/models/order.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 uniqueness_of_name has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def uniqueness_of_name
        matches = Article.where(name: name, supplier_id: supplier_id, deleted_at: deleted_at, type: type)
        matches = matches.where.not(id: id) unless new_record?
        # supplier should always be there - except, perhaps, on initialization (on seeding)
        if supplier && (supplier.shared_sync_method.blank? || supplier.shared_sync_method == 'import')
    Severity: Minor
    Found in app/models/article.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 find_match has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.find_match(category)
        return if category.blank? || category.length < 3
    
        c = nil
        ## exact match - not needed, will be returned by next query as well
    Severity: Minor
    Found in app/models/article_category.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 link_to_ordering has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def link_to_ordering(order, options = {}, &block)
        group_order = order.group_order(current_user.ordergroup)
        path = if options[:show] && group_order
                 group_order_path(group_order)
               elsif group_order
    Severity: Minor
    Found in app/helpers/group_orders_helper.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_financial_transaction! has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def add_financial_transaction!(amount, note, user, transaction_type, link = nil, group_order = nil)
    Severity: Minor
    Found in app/models/ordergroup.rb - About 45 mins to fix

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

        def show
          link = Link.find(params[:id])
          url = link.url
      
          return deny_access if link.workgroup && !current_user.role_admin? && !link.workgroup.member?(current_user)
      Severity: Minor
      Found in plugins/links/app/controllers/links_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 find_in_batches_with_order has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def find_in_batches_with_order(options = {})
            options.assert_valid_keys(:batch_size)
      
            relation = self
      
      
      Severity: Minor
      Found in app/models/concerns/find_each_with_order.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 pkg_helper has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def pkg_helper(article, options = {})
          return '' if !article || article.unit_quantity == 1
      
          uq_text = "× #{article.unit_quantity}"
          uq_text = content_tag(:span, uq_text, class: 'hidden-phone') if options[:soft_uq]
      Severity: Minor
      Found in app/helpers/orders_helper.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 index has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def index
          sort = if params['sort']
                   case params['sort']
                   when 'name' then 'articles.name'
                   when 'unit' then 'articles.unit'
      Severity: Minor
      Found in app/controllers/articles_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 parse has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.parse(file, options = {})
          filepath = file.is_a?(String) ? file : file.to_path
          filename = options.delete(:filename) || filepath
          fileext = File.extname(filename)
          options[:csv_options] = { col_sep: ';', encoding: 'utf-8' }.merge(options[:csv_options] || {})
      Severity: Minor
      Found in app/lib/spreadsheet_file.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