ArtOfCode-/qpixel

View on GitHub
app/models/post.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Class Post has 31 methods (exceeds 20 allowed). Consider refactoring.
Open

class Post < ApplicationRecord
  include CommunityRelated

  belongs_to :user
  belongs_to :post_type
Severity: Minor
Found in app/models/post.rb - About 3 hrs to fix

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

      def moderator_tags
        mod_tags = category&.moderator_tags&.map(&:name)
        return unless mod_tags.present? && !mod_tags.empty?
        return if RequestContext.user&.is_moderator
    
    
    Severity: Minor
    Found in app/models/post.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 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 check_attribution_notice has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def check_attribution_notice
        sc = saved_changes
        attributes = ['att_source', 'att_license_name', 'att_license_link']
        if attributes.any? { |x| sc.include?(x) && sc[x][0] != sc[x][1] }
          if attributes.all? { |x| sc[x]&.try(:[], 0).nil? }
    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

    There are no issues that match your filters.

    Category
    Status