otwcode/otwarchive

View on GitHub
app/models/tag.rb

Summary

Maintainability
F
5 days
Test Coverage

File tag.rb has 836 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "unicode_utils/casefold"

class Tag < ApplicationRecord
  include Searchable
  include StringCleaner
Severity: Major
Found in app/models/tag.rb - About 2 days to fix

    Class Tag has 103 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Tag < ApplicationRecord
      include Searchable
      include StringCleaner
      include WorksOwner
      include Wrangleable
    Severity: Major
    Found in app/models/tag.rb - About 1 day to fix

      Method check_synonym has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def check_synonym
          if !self.new_record? && self.name_changed?
            # ordinary wranglers can change case and accents but not punctuation or the actual letters in the name
            # admins can change tags with no restriction
            unless User.current_user.is_a?(Admin) || only_case_changed?
      Severity: Minor
      Found in app/models/tag.rb - About 1 hr 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 after_update has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def after_update
          tag = self
          if tag.saved_change_to_canonical?
            if tag.canonical
              # newly canonical tag
      Severity: Minor
      Found in app/models/tag.rb - About 1 hr 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 syn_string= has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def syn_string=(tag_string)
          # If the tag_string is blank, our tag should be given no merger
          if tag_string.blank?
            self.merger_id = nil
            return
      Severity: Minor
      Found in app/models/tag.rb - About 1 hr 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 commentable_owners has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def commentable_owners
          # if the tag is a fandom, grab its wranglers or the wranglers of its canonical merger
          if self.is_a?(Fandom)
            self.canonical? ? self.wranglers : (self.merger_id ? self.merger.wranglers : [])
          # if the tag is any other tag, try to grab all the wranglers of all its parent fandoms, if applicable
      Severity: Minor
      Found in app/models/tag.rb - About 1 hr 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 after_update has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def after_update
          tag = self
          if tag.saved_change_to_canonical?
            if tag.canonical
              # newly canonical tag
      Severity: Minor
      Found in app/models/tag.rb - About 1 hr to fix

        Method syn_string= has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def syn_string=(tag_string)
            # If the tag_string is blank, our tag should be given no merger
            if tag_string.blank?
              self.merger_id = nil
              return
        Severity: Minor
        Found in app/models/tag.rb - About 1 hr to fix

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

            def self.find_or_create_by_name(new_name)
              if new_name && new_name.is_a?(String)
                new_name.squish!
                tag = Tag.find_by_name(new_name)
                # if the tag exists and has the proper class, or it is an unsorted tag and it can be sorted to the self class
          Severity: Minor
          Found in app/models/tag.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 filter has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def filter
              self.canonical? ? self : ((self.merger && self.merger.canonical?) ? self.merger : nil)
            end
          Severity: Minor
          Found in app/models/tag.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 autocomplete_fandom_lookup has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.autocomplete_fandom_lookup(options = {})
              options.reverse_merge!({term: "", tag_type: "character", fandom: "", fallback: true})
              search_param = options[:term]
              tag_type = options[:tag_type]
              fandoms = Tag.get_search_terms(options[:fandom])
          Severity: Minor
          Found in app/models/tag.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

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

            def self.by_name_without_articles(fieldname = "name")
              fieldname = "name" unless fieldname.match(/^([\w]+\.)?[\w]+$/)
              order(Arel.sql("case when lower(substring(#{fieldname} from 1 for 4)) = 'the ' then substring(#{fieldname} from 5)
                      when lower(substring(#{fieldname} from 1 for 2)) = 'a ' then substring(#{fieldname} from 3)
                      when lower(substring(#{fieldname} from 1 for 3)) = 'an ' then substring(#{fieldname} from 4)
          Severity: Minor
          Found in app/models/tag.rb and 1 other location - About 35 mins to fix
          app/models/tagset_models/tag_set_association.rb on lines 16..21

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

          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

          There are no issues that match your filters.

          Category
          Status