discourse/discourse

View on GitHub

Showing 1,539 of 1,848 total issues

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

  def backwards_compatible_json(json_obj, success)
    json_obj.symbolize_keys!
    if params[:nested_post].blank? && json_obj[:errors].blank? && json_obj[:action] != :enqueued
      json_obj = json_obj[:post]
    end
Severity: Minor
Found in app/controllers/posts_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 remove_allowed_user has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def remove_allowed_user
    params.require(:username)
    topic = Topic.find_by(id: params[:topic_id])
    raise Discourse::NotFound unless topic
    user = User.find_by(username: params[:username])
Severity: Minor
Found in app/controllers/topics_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 post_stream has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def post_stream
    result = { posts: posts }

    if include_stream?
      if !object.is_mega_topic?
Severity: Minor
Found in app/serializers/post_stream_serializer_mixin.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 cooked has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def cooked
    if cooked_hidden
      if scope.current_user && object.user_id == scope.current_user.id
        I18n.t('flagging.you_must_edit', path: "/my/messages")
      else
Severity: Minor
Found in app/serializers/basic_post_serializer.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 post_needs_approval_in_its_category? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def self.post_needs_approval_in_its_category?(manager)
    if manager.args[:topic_id].present?
      cat = Category.joins(:topics).find_by(topics: { id: manager.args[:topic_id] })
      return false unless cat
      cat.require_reply_approval?
Severity: Minor
Found in lib/new_post_manager.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 migrate_child has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def migrate_child(parent, top_parent)
    unless already_exists?(top_parent.parent_theme_id, parent.child_theme_id)
      execute("
        INSERT INTO child_themes (parent_theme_id, child_theme_id, created_at, updated_at)
        VALUES (#{top_parent.parent_theme_id}, #{parent.child_theme_id}, now(), now())
Severity: Minor
Found in db/migrate/20180710172959_disallow_multi_levels_theme_components.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 next has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def self.next(count, category = nil)
    key = cache_key(category)

    results = []

Severity: Minor
Found in app/services/random_topic_selector.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 each_globbed_asset has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def each_globbed_asset
    if @path
      # Automatically include all ES6 JS and hbs files
      root_path = "#{File.dirname(@path)}/assets/javascripts"

Severity: Minor
Found in lib/plugin/instance.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 add_to_reverse_index has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def add_to_reverse_index(url, post_id)
    # make sure we have a url to insert
    return unless url.present?
    # local uploads are relative
    if index = url.index(local_base_url)
Severity: Minor
Found in db/migrate/20131014203951_backfill_post_upload_reverse_index.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 change has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def change(asynchronous: true, run_update_job: true)
    @user.username = @new_username

    if @user.save
      if @actor && @old_username != @new_username
Severity: Minor
Found in app/services/username_changer.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 post_action_rows has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def self.post_action_rows(post_action)
    action = UserAction::BOOKMARK if post_action.is_bookmark?
    action = UserAction::LIKE if post_action.is_like?
    return [] unless action

Severity: Minor
Found in app/services/user_action_manager.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 log_topic_delete_recover has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def log_topic_delete_recover(topic, action = "delete_topic", opts = {})
    raise Discourse::InvalidParameters.new(:topic) unless topic && topic.is_a?(Topic)

    user = topic.user ? "#{topic.user.username} (#{topic.user.name})" : "(deleted user)"

Severity: Minor
Found in app/services/staff_action_logger.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 can_see_topic? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def can_see_topic?(topic, hide_deleted = true)
    return false unless topic
    return true if is_admin?
    return false if hide_deleted && topic.deleted_at && !can_see_deleted_topics?

Severity: Minor
Found in lib/guardian/topic_guardian.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 can_edit_email? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def can_edit_email?(user)
    return false if SiteSetting.sso_overrides_email? && SiteSetting.enable_sso?
    return false unless SiteSetting.email_editable?
    return true if is_staff?
    return false if is_anonymous?
Severity: Minor
Found in lib/guardian/user_guardian.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 can_edit_username? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def can_edit_username?(user)
    return false if SiteSetting.sso_overrides_username? && SiteSetting.enable_sso?
    return true if is_staff?
    return false if SiteSetting.username_change_period <= 0
    return false if is_anonymous?
Severity: Minor
Found in lib/guardian/user_guardian.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 can_edit_name? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def can_edit_name?(user)
    return false unless SiteSetting.enable_names?
    return false if SiteSetting.sso_overrides_name? && SiteSetting.enable_sso?
    return true if is_staff?
    return false if is_anonymous?
Severity: Minor
Found in lib/guardian/user_guardian.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 check_missing_site_options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def check_missing_site_options
    unless SiteSetting.s3_use_iam_profile
      raise SettingMissing.new("access_key_id") if SiteSetting.s3_access_key_id.blank?
      raise SettingMissing.new("secret_access_key") if SiteSetting.s3_secret_access_key.blank?
    end
Severity: Minor
Found in lib/s3_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 theme has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def theme
      unless @theme
        @theme = (@theme_id && Theme.find(@theme_id)) || :nil
      end
      @theme == :nil ? nil : @theme
Severity: Minor
Found in lib/stylesheet/importer.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 flagged_post_actions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def self.flagged_post_actions(opts = nil)
    Discourse.deprecate("FlagQuery is deprecated, please use the Reviewable API instead.", since: "2.3.0beta5", drop_from: "2.4")

    opts ||= {}

Severity: Minor
Found in lib/flag_query.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 cannot_delete_category_reason has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def cannot_delete_category_reason(category)
    return I18n.t('category.cannot_delete.uncategorized') if category.uncategorized?
    return I18n.t('category.cannot_delete.has_subcategories') if category.has_children?

    if category.topic_count != 0
Severity: Minor
Found in lib/guardian/category_guardian.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