app/models/attachment.rb
Class Attachment
has 27 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class Attachment < ApplicationRecord
belongs_to :parent, polymorphic: true
belongs_to :parent_group, -> { where(attachments: {parent_type: "Group"}).includes(:attachments) }, foreign_key: :parent_id, class_name: "Group"
belongs_to :parent_page, -> { where(attachments: {parent_type: "Page"}).includes(:attachments) }, foreign_key: :parent_id, class_name: "Page"
Method thumb_path
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
Open
def thumb_path
url = file.url if has_type?("svg")
url ||= file.url(:thumb) if has_type?("image") or has_type?("pdf")
url ||= file.url(:video_thumb) if has_type?("video")
url ||= helpers.image_path('file.png')
- Read upRead up
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 find_without_types
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def self.find_without_types( *types )
self.all.to_a.collect do |attachment|
re = attachment
for type in types
if not attachment.content_type
- Read upRead up
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"