znamenica/dneslov

View on GitHub
app/services/image_sync_service.rb

Summary

Maintainability
C
1 day
Test Coverage

Class ImageSyncService has 29 methods (exceeds 20 allowed). Consider refactoring.
Open

class ImageSyncService
   attr_reader :targets, :source, :storage, :asset_path

   def initialize source: nil, targets: [], asset_path: nil, storage: nil
      @source = source # path
Severity: Minor
Found in app/services/image_sync_service.rb - About 3 hrs to fix

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

       def load
          unassigned = Resource.unassigned.image
          objects =
             unassigned.map do |r|
                info = Memory.find_by(short_name: r[:props]['short_name'])
    Severity: Minor
    Found in app/services/image_sync_service.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 info has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

       def info file
          imageinfo = `identify "#{esc(file)}" 2>&1`.strip
          fileinfo = `file -- "#{esc(file)}" 2>&1`.strip
    
          unless /(?<type>GIF|JPEG|WEBP|PNG|BMP3?) (?<width>\d+)x(?<height>\d+)/ =~ imageinfo
    Severity: Minor
    Found in app/services/image_sync_service.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 load has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

       def load
          unassigned = Resource.unassigned.image
          objects =
             unassigned.map do |r|
                info = Memory.find_by(short_name: r[:props]['short_name'])
    Severity: Minor
    Found in app/services/image_sync_service.rb - About 1 hr to fix

      Method attrs has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

         def attrs
            @attrs ||=
               folders.map do |folder|
                  fbase = File.basename(folder)
                  target_path = File.join(now.strftime("%Y"), now.strftime("%m"), now.strftime("%Y%m%d%H%M%S"))
      Severity: Minor
      Found in app/services/image_sync_service.rb - About 1 hr to fix

        Method copy has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

           def copy source, target, type, kind, scheme
        Severity: Minor
        Found in app/services/image_sync_service.rb - About 35 mins to fix

          Method validates has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

             def validates scheme
                scheme[:attrs].each do |a|
                   duped = duped(a)
          
                   error("Invalid height of image file #{a[:source]}") if a[:kind] == :invalid
          Severity: Minor
          Found in app/services/image_sync_service.rb - About 35 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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

             def initialize source: nil, targets: [], asset_path: nil, storage: nil
                @source = source # path
                @targets = targets # paths
                @asset_path = asset_path || '/images'
                @storage = Rails.root.join(storage || 'public/images')
          Severity: Minor
          Found in app/services/image_sync_service.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

          dynamic constant assignment (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
          Open

             KEYS = %i(short_name comment imageinfo fileinfo kind width height hash event)
          Severity: Minor
          Found in app/services/image_sync_service.rb by rubocop

          unexpected token kDO_BLOCK (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
          Open

                   Dir.chdir(resource_path) do
          Severity: Minor
          Found in app/services/image_sync_service.rb by rubocop

          unexpected token tRBRACK (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
          Open

                [type&.downcase&.to_sym, imageinfo, fileinfo, kind, width.to_i, height.to_i]
          Severity: Minor
          Found in app/services/image_sync_service.rb by rubocop

          unexpected token error (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
          Open

                time = Resource.order(updated_at: :desc).first&.updated_at || Time.at(0) # last for updated_at or settingize
          Severity: Minor
          Found in app/services/image_sync_service.rb by rubocop

          unexpected token kEND (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
          Open

          end
          Severity: Minor
          Found in app/services/image_sync_service.rb by rubocop

          unexpected token error (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
          Open

                [type&.downcase&.to_sym, imageinfo, fileinfo, kind, width.to_i, height.to_i]
          Severity: Minor
          Found in app/services/image_sync_service.rb by rubocop

          unexpected token kDO_BLOCK (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
          Open

                      Dir['.schemes/**/*.yaml'].select do |f|
          Severity: Minor
          Found in app/services/image_sync_service.rb by rubocop

          There are no issues that match your filters.

          Category
          Status