discourse/discourse

View on GitHub
lib/discourse_tagging.rb

Summary

Maintainability
D
2 days
Test Coverage

Method filter_allowed_tags has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

  def self.filter_allowed_tags(query, guardian, opts = {})
    selected_tag_ids = opts[:selected_tags] ? Tag.where_name(opts[:selected_tags]).pluck(:id) : []

    if !opts[:for_topic] && !selected_tag_ids.empty?
      query = query.where('tags.id NOT IN (?)', selected_tag_ids)
Severity: Minor
Found in lib/discourse_tagging.rb - About 6 hrs 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_topic_by_names has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

  def self.tag_topic_by_names(topic, guardian, tag_names_arg, append: false)
    if guardian.can_tag?(topic)
      tag_names = DiscourseTagging.tags_for_saving(tag_names_arg, guardian) || []

      old_tag_names = topic.tags.pluck(:name) || []
Severity: Minor
Found in lib/discourse_tagging.rb - About 5 hrs 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 filter_allowed_tags has 87 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.filter_allowed_tags(query, guardian, opts = {})
    selected_tag_ids = opts[:selected_tags] ? Tag.where_name(opts[:selected_tags]).pluck(:id) : []

    if !opts[:for_topic] && !selected_tag_ids.empty?
      query = query.where('tags.id NOT IN (?)', selected_tag_ids)
Severity: Major
Found in lib/discourse_tagging.rb - About 3 hrs to fix

    Method tag_topic_by_names has 63 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.tag_topic_by_names(topic, guardian, tag_names_arg, append: false)
        if guardian.can_tag?(topic)
          tag_names = DiscourseTagging.tags_for_saving(tag_names_arg, guardian) || []
    
          old_tag_names = topic.tags.pluck(:name) || []
    Severity: Major
    Found in lib/discourse_tagging.rb - About 2 hrs to fix

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

        def self.tags_for_saving(tags_arg, guardian, opts = {})
      
          return [] unless guardian.can_tag_topics? && tags_arg.present?
      
          tag_names = Tag.where_name(tags_arg).pluck(:name)
      Severity: Minor
      Found in lib/discourse_tagging.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

      There are no issues that match your filters.

      Category
      Status