rogercampos/saviour

View on GitHub

Showing 19 of 19 total issues

Method setup! has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
Open

    def setup!
      raise(ConfigurationError, "You cannot include Saviour::Model twice in the same class") if @klass.respond_to?(:attached_files)

      @klass.class_attribute :attached_files
      @klass.attached_files = []
Severity: Minor
Found in lib/saviour/integrator.rb - About 1 day 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 setup! has 120 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def setup!
      raise(ConfigurationError, "You cannot include Saviour::Model twice in the same class") if @klass.respond_to?(:attached_files)

      @klass.class_attribute :attached_files
      @klass.attached_files = []
Severity: Major
Found in lib/saviour/integrator.rb - About 4 hrs to fix

    Class File has 21 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class File
        attr_reader :persisted_path, :source, :storage
    
        def initialize(uploader_klass, model, attached_as, persisted_path = nil)
          @uploader_klass, @model, @attached_as = uploader_klass, model, attached_as
    Severity: Minor
    Found in lib/saviour/file.rb - About 2 hrs to fix

      Method process_upload has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def process_upload(klass, touch: false)
            persistence_layer = @persistence_klass.new(@model)
      
            uploaders = attached_files.map do |column|
              next unless @model.send(column).changed?
      Severity: Minor
      Found in lib/saviour/life_cycle.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 process_upload has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def process_upload(klass, touch: false)
            persistence_layer = @persistence_klass.new(@model)
      
            uploaders = attached_files.map do |column|
              next unless @model.send(column).changed?
      Severity: Minor
      Found in lib/saviour/life_cycle.rb - About 1 hr to fix

        Method write has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def write(before_write: nil)
              raise(MissingSource, "You must provide a source to read from before trying to write") unless @source
        
              __maybe_with_tmpfile(source_type, @source) do |tmpfile|
                contents, path = case source_type
        Severity: Minor
        Found in lib/saviour/file.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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

              def run_validation(method_or_block)
                opts = { attached_as: @column }
        
                if method_or_block.respond_to?(:call)
                  if method_or_block.arity == 2
        Severity: Minor
        Found in lib/saviour/validator.rb and 1 other location - About 55 mins to fix
        lib/saviour/validator.rb on lines 81..94

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 46.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

              def run_validation_as_file(method_or_block)
                opts = { attached_as: @column }
        
                if method_or_block.respond_to?(:call)
                  if method_or_block.arity == 2
        Severity: Minor
        Found in lib/saviour/validator.rb and 1 other location - About 55 mins to fix
        lib/saviour/validator.rb on lines 63..76

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 46.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Method assign has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def assign(object)
              raise(SourceError, "given object to #assign or #<attach_as>= must respond to `read`") if object && !object.respond_to?(:read)
        
              followers = @model.class.followers_per_leader_config[@attached_as]
        
        
        Severity: Minor
        Found in lib/saviour/file.rb - About 55 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 upload has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def upload
                dup_temp_path = SecureRandom.hex
        
                dup_file = proc do
                  uploader.storage.cp @current_path, dup_temp_path
        Severity: Minor
        Found in lib/saviour/life_cycle.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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            def _process_as_contents(contents, filename)
              raise ConfigurationError, "Please use `store_dir` in the uploader" unless store_dir
        
              catch(:halt_process) do
                if Config.processing_enabled
        Severity: Minor
        Found in lib/saviour/base_uploader.rb and 1 other location - About 35 mins to fix
        lib/saviour/base_uploader.rb on lines 37..47

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 34.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            def _process_as_file(file, filename)
              raise ConfigurationError, "Please use `store_dir` in the uploader" unless store_dir
        
              catch(:halt_process) do
                if Config.processing_enabled
        Severity: Minor
        Found in lib/saviour/base_uploader.rb and 1 other location - About 35 mins to fix
        lib/saviour/base_uploader.rb on lines 23..33

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 34.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

              def storage
                @semaphore.synchronize do
                  Thread.current.thread_variable_set("Saviour::Config", {}) unless Thread.current.thread_variable_get("Saviour::Config")
                  Thread.current.thread_variable_get("Saviour::Config")[:storage] || (Thread.main.thread_variable_get("Saviour::Config") && Thread.main.thread_variable_get("Saviour::Config")[:storage]) || NotImplemented.new
                end
        Severity: Minor
        Found in lib/saviour/config.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 == has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def ==(another_file)
              return false unless another_file.is_a?(Saviour::File)
              return false unless another_file.persisted? == persisted?
        
              if persisted?
        Severity: Minor
        Found in lib/saviour/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

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

              def run_validation(method_or_block)
                opts = { attached_as: @column }
        
                if method_or_block.respond_to?(:call)
                  if method_or_block.arity == 2
        Severity: Minor
        Found in lib/saviour/validator.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 run_validation_as_file has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def run_validation_as_file(method_or_block)
                opts = { attached_as: @column }
        
                if method_or_block.respond_to?(:call)
                  if method_or_block.arity == 2
        Severity: Minor
        Found in lib/saviour/validator.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 ensure_removed_empty_dir has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def ensure_removed_empty_dir(path)
              basedir = ::File.dirname(path)
              return if basedir == "."
        
              while basedir != "/" && basedir != "." && Dir.entries(real_path(basedir)) - [".", ".."] == []
        Severity: Minor
        Found in lib/saviour/local_storage.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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

              @klass.define_singleton_method("attach_validation_with_file") do |attach_as, method_name = nil, &block|
                self.__saviour_validations = self.__saviour_validations.dup
                self.__saviour_validations[attach_as] += [{ method_or_block: method_name || block, type: :file }]
              end
        Severity: Minor
        Found in lib/saviour/integrator.rb and 1 other location - About 15 mins to fix
        lib/saviour/integrator.rb on lines 154..157

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 26.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

              @klass.define_singleton_method("attach_validation") do |attach_as, method_name = nil, &block|
                self.__saviour_validations = self.__saviour_validations.dup
                self.__saviour_validations[attach_as] += [{ method_or_block: method_name || block, type: :memory }]
              end
        Severity: Minor
        Found in lib/saviour/integrator.rb and 1 other location - About 15 mins to fix
        lib/saviour/integrator.rb on lines 159..162

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 26.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Severity
        Category
        Status
        Source
        Language