foodcoop-adam/foodsoft

View on GitHub

Showing 150 of 150 total issues

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

  def select_foodcoop
    if FoodsoftConfig[:multi_coop_install]
      if params[:foodcoop].present?
        begin
          # Set Config and database connection
Severity: Minor
Found in app/controllers/application_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 set_mollie_cfg has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def set_mollie_cfg
    if mcfg = FoodsoftConfig[:mollie].try(&:symbolize_keys)
      IdealMollie::Config.partner_id  = mcfg[:partner_id]  if mcfg[:partner_id]
      IdealMollie::Config.profile_key = mcfg[:profile_key] if mcfg[:profile_key]
      IdealMollie::Config.test_mode   = mcfg[:test_mode]   if mcfg[:test_mode]
Severity: Minor
Found in lib/foodsoft_mollie/app/controllers/payments/mollie_ideal_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 signup_warning has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def self.signup_warning(c, user)
    FoodsoftSignup.enabled? :approval or return true
    return true if FoodsoftConfig[:unapproved_allow_access]=='*'
    if user
      user.role_admin? and return true
Severity: Minor
Found in lib/foodsoft_signup/lib/foodsoft_signup/hooks.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 create_from_upload has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def create_from_upload
    begin
      Article.transaction do
        invalid_articles = false
        @articles = []
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

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

    if params["sort"]
      sort = case params["sort"]
               when "name" then "name"
               when "account_balance" then "account_balance"
               when "name_reverse" then "name DESC"
Severity: Minor
Found in app/controllers/finance/ordergroups_controller.rb and 2 other locations - About 35 mins to fix
app/controllers/finance/financial_transactions_controller.rb on lines 10..20
app/controllers/home_controller.rb on lines 32..42

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

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

  def user_list=(ids)
    list = ids.split(",").map(&:to_i)
    new_users = (list - users.collect(&:id)).uniq
    old_users = users.reject { |user| list.include?(user.id) }
    
Severity: Minor
Found in app/models/task.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 uniqueness_of_name has a Cognitive Complexity of 7 (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('id != ?', id) unless new_record?
    if supplier.shared_sync_method.blank? or supplier.shared_sync_method == 'import'
      errors.add :name, :taken if matches.any?
Severity: Minor
Found in app/models/article.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 accept_invitation has a Cognitive Complexity of 7 (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 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

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

    if params['sort']
      sort = case params['sort']
               when "date"  then "created_on"
               when "note"   then "note"
               when "amount" then "amount"
Severity: Minor
Found in app/controllers/finance/financial_transactions_controller.rb and 2 other locations - About 35 mins to fix
app/controllers/finance/ordergroups_controller.rb on lines 4..14
app/controllers/home_controller.rb on lines 32..42

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

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

  def create_collection
    raise I18n.t('finance.financial_transactions.controller.create_collection.error_note_required') if params[:note].blank?
    params[:financial_transactions].each do |trans|
      # ignore empty amount fields ...
      unless trans[:amount].blank?
Severity: Minor
Found in app/controllers/finance/financial_transactions_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 login has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def login
    # use cookies, but allow to get them from parameters (if on other domain)
    sweets = params.select {|k,v| k=='Mem' or k=='Key'}
    sweets.empty? and sweets = cookies

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

        def add_order_result_attachments
          foodsoft_orderdoc_add_order_result_attachments
          if FoodsoftOrderdoc.enabled? and FoodsoftOrderdoc.supplier_has_orderdoc?(@order.supplier)
            Rails.logger.debug "Adding orderdoc to supplier mail for order #{@order.id}"
            orderdoc = FoodsoftOrderdoc.orderdoc(@order)
Severity: Minor
Found in lib/foodsoft_orderdoc/lib/foodsoft_orderdoc/add_to_supplier_mail.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 show has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def show
    require 'csv'
    @users = select_users(:all)
    fields = [:id, :name, :email, :phone, :ordergroup]
    fields << :approved if defined? FoodsoftSignup
Severity: Minor
Found in lib/foodsoft_mailall/app/controllers/admin/mailall_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 pkg_helper has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def pkg_helper(article, options={})
    return '' if not article or article.unit_quantity == 1
    uq_text = "× #{article.unit_quantity}"
    uq_text = content_tag(:span, uq_text, class: 'hidden-phone') if options[:soft_uq]
    if options[:plain]
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

Avoid too many return statements within this method.
Open

    return array();
Severity: Major
Found in lib/foodsoft_userinfo/examples/phpbb3_auth_foodsoft.php - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

        return $row;
    Severity: Major
    Found in lib/foodsoft_userinfo/examples/phpbb3_auth_foodsoft.php - About 30 mins to fix

      Method keep_ordered_articles has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def keep_ordered_articles
          chosen_order_articles = order_articles.find_all_by_article_id(article_ids)
          to_be_removed = order_articles - chosen_order_articles
          to_be_removed_but_ordered = to_be_removed.select { |a| a.quantity > 0 or a.tolerance > 0 }
          unless to_be_removed_but_ordered.empty? or ignore_warnings
      Severity: Minor
      Found in app/models/order.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 payment_link has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.payment_link(c)
          (s = FoodsoftConfig[:ordergroup_approval_payment]) or return nil
          url = if s.match(/^https?:/i)
            s
          else
      Severity: Minor
      Found in lib/foodsoft_signup/lib/foodsoft_signup.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 expand has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def expand
          @users = {}
          @users[:all] = select_users :all
          @users[:current] = select_users :current
          @users[:approved] = select_users :approved if defined? FoodsoftSignup
      Severity: Minor
      Found in lib/foodsoft_mailall/app/controllers/admin/mailall_controller.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 index has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def index
          if params["sort"]
            sort = case params["sort"]
                     when "name" then "name"
                     when "account_balance" then "account_balance"
      Severity: Minor
      Found in app/controllers/finance/ordergroups_controller.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

      Severity
      Category
      Status
      Source
      Language