ArtOfCode-/qpixel

View on GitHub

Showing 164 of 164 total issues

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

  def check_your_privilege(name, post = nil, render_error = true)
    unless current_user&.privilege?(name) || (current_user&.has_post_privilege?(name, post) if post)
      @privilege = Ability.find_by(name: name)
      render 'errors/forbidden', layout: 'without_sidebar', privilege_name: name, status: :forbidden if render_error
      return false
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 update_tag_associations has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def update_tag_associations
    return if tags_cache.nil? # Don't update if this doesn't affect tags

    tags_cache.each do |tag_name|
      tag = Tag.find_or_create_by name: tag_name, tag_set: post.category.tag_set
Severity: Minor
Found in app/models/suggested_edit.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 expandable? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def expandable?
    (defined?(@category) && !@category.nil? && !current_page?(new_category_path)) ||
      (defined?(@post) && !@post.category.nil?) ||
      (defined?(@question) && !@question.category.nil?) ||
      (defined?(@article) && !@article.category.nil?)
Severity: Minor
Found in app/helpers/categories_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

Identical blocks of code found in 2 locations. Consider refactoring.
Open

      var start = t.selectionStart,
        end = t.selectionEnd,
        text = t.value,
        chr = $(this).data('t');
Severity: Minor
Found in public/assets/community/judaism.js and 1 other location - About 35 mins to fix
public/assets/community/judaism.js on lines 154..157

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

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

Identical blocks of code found in 2 locations. Consider refactoring.
Open

      var start = t.selectionStart,
        end = t.selectionEnd,
        text = t.value,
        chr = $(this).data('t');
Severity: Minor
Found in public/assets/community/judaism.js and 1 other location - About 35 mins to fix
public/assets/community/judaism.js on lines 168..171

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

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

Avoid too many return statements within this method.
Open

      return false if !priv.flag_score_threshold.nil? && flag_score < priv.flag_score_threshold
Severity: Major
Found in app/models/community_user.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

          return
    Severity: Major
    Found in app/controllers/posts_controller.rb - About 30 mins to fix

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

        def recalc_trust_level
          trust = if user.staff?
                    5
                  elsif is_moderator || user.is_global_moderator || is_admin || user.is_global_admin
                    4
      Severity: Minor
      Found in app/models/community_user.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 update_tag_associations has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def update_tag_associations
          tags_cache.each do |tag_name|
            tag = Tag.find_or_create_by name: tag_name, tag_set: category.tag_set
            unless tags.include? tag
              tags << tag
      Severity: Minor
      Found in app/models/post.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 article_ad has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def article_ad(article)
          ad = Rails.cache.fetch "posts/#{article.id}/ad", expires_in: 60.minutes do
            ad = Image.new(600, 500)
            ad.background_color = 'white'
      
      
      Severity: Minor
      Found in app/controllers/advertisement_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

      Function HBKeyboard has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      (function HBKeyboard() {
        var docCookies = { //from developer.mozilla.org/en-US/docs/Web/API/document.cookie
          getItem: function (sKey) {
            return unescape(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
          },
      Severity: Minor
      Found in public/assets/community/judaism.js - 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_globals has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def set_globals
          setup_request_context || return
          setup_user
      
          pull_pinned_links_and_hot_questions
      Severity: Minor
      Found in app/controllers/application_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 tag_classes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def tag_classes(tag, category)
          required_ids = category&.required_tag_ids
          moderator_ids = category&.moderator_tag_ids
          topic_ids = category&.topic_tag_ids
          required = required_ids&.include?(tag.id) ? 'is-filled' : ''
      Severity: Minor
      Found in app/helpers/tags_helper.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 destroy has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def destroy
          @subscription = Subscription.find params[:id]
          if current_user.is_admin || current_user.id == @subscription.user_id
            if @subscription.destroy
              render json: { status: 'success' }
      Severity: Minor
      Found in app/controllers/subscriptions_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

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

        def login_email
          user = params[:user]
          @host = params[:host]
          @token = SecureRandom.urlsafe_base64(64)
          user.update(login_token: @token, login_token_expires_at: 5.minutes.from_now)
      Severity: Minor
      Found in app/mailers/two_factor_mailer.rb and 1 other location - About 25 mins to fix
      app/mailers/two_factor_mailer.rb on lines 4..10

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

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

        def new
          type = if params[:flag_type].present?
                   PostFlagType.find params[:flag_type]
                 end
      
      
      Severity: Minor
      Found in app/controllers/flags_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 create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          suspension_duration = params[:mod_warning][:suspension_duration].to_i
      
          suspension_duration = 1 if suspension_duration <= 0
          suspension_duration = 365 if suspension_duration > 365
      Severity: Minor
      Found in app/controllers/mod_warning_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 approve has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def approve
          unless @edit.active?
            render json: { status: 'error', message: 'This edit has already been reviewed.' }, status: :conflict
            return
          end
      Severity: Minor
      Found in app/controllers/suggested_edit_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
          links = if current_user.is_global_moderator && params[:global] == '2'
                    PinnedLink.unscoped
                  elsif current_user.is_global_moderator && params[:global] == '1'
                    PinnedLink.where(community: nil)
      Severity: Minor
      Found in app/controllers/pinned_links_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

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

        def disable_email
          user = params[:user]
          @host = params[:host]
          @token = SecureRandom.urlsafe_base64(64)
          user.update(login_token: @token, login_token_expires_at: 5.minutes.from_now)
      Severity: Minor
      Found in app/mailers/two_factor_mailer.rb and 1 other location - About 25 mins to fix
      app/mailers/two_factor_mailer.rb on lines 12..18

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

      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

      Severity
      Category
      Status
      Source
      Language