otwcode/otwarchive

View on GitHub
app/models/tagset_models/tag_set.rb

Summary

Maintainability
C
1 day
Test Coverage

Method assign_tags has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  def assign_tags
    tags_to_add = []
    tags_to_remove = []

    TAG_TYPES.each do |type|
Severity: Minor
Found in app/models/tagset_models/tag_set.rb - About 2 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

Class TagSet has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

class TagSet < ApplicationRecord
  # a complete match is numerically represented with ALL
  ALL = -1

  TAG_TYPES = %w(fandom character relationship freeform category rating archive_warning)
Severity: Minor
Found in app/models/tagset_models/tag_set.rb - About 2 hrs to fix

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

      def tagnames_must_exist
        nonexist = []
        if @tagnames
          nonexist += @tagnames.split(ArchiveConfig.DELIMITER_FOR_INPUT).select {|t| !Tag.where(name: t.squish).exists?}
        end
    Severity: Minor
    Found in app/models/tagset_models/tag_set.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 tagnames_to_list has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def tagnames_to_list(taglist, type=nil)
          taglist = (taglist.kind_of?(String) ? taglist.split(ArchiveConfig.DELIMITER_FOR_INPUT) : taglist).uniq
          if type
            raise "Redshirt: Attempted to constantize invalid class initialize tagnames_to_list #{type}" unless TAG_TYPES.include?(type)
            if Tag::USER_DEFINED.include?(type.classify)
    Severity: Minor
    Found in app/models/tagset_models/tag_set.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 assign_tags has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def assign_tags
        tags_to_add = []
        tags_to_remove = []
    
        TAG_TYPES.each do |type|
    Severity: Minor
    Found in app/models/tagset_models/tag_set.rb - About 1 hr to fix

      There are no issues that match your filters.

      Category
      Status