tasafo/palestras-coletivas

View on GitHub
app/services/image_file.rb

Summary

Maintainability
A
25 mins
Test Coverage
B
87%

ImageFile#self.remove manually dispatches method call
Open

      Cloudinary::Uploader.destroy(file.public_id) if file.respond_to?(:public_id)
Severity: Minor
Found in app/services/image_file.rb by reek

Reek reports a Manual Dispatch smell if it finds source code that manually checks whether an object responds to a method before that method is called. Manual dispatch is a type of Simulated Polymorphism which leads to code that is harder to reason about, debug, and refactor.

Example

class MyManualDispatcher
  attr_reader :foo

  def initialize(foo)
    @foo = foo
  end

  def call
    foo.bar if foo.respond_to?(:bar)
  end
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [9]: MyManualDispatcher manually dispatches method call (ManualDispatch)

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

  def self.remove(file)
    if CloudinaryReady.up?
      Cloudinary::Uploader.destroy(file.public_id) if file.respond_to?(:public_id)
    else
      file_path = file.path
Severity: Minor
Found in app/services/image_file.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