carrierwaveuploader/carrierwave

View on GitHub

Showing 51 of 51 total issues

Method process! has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def process!(new_file=nil)
        return unless enable_processing

        with_callbacks(:process, new_file) do
          self.class.processors.each do |method, args, condition, condition_type|
Severity: Minor
Found in lib/carrierwave/uploader/processing.rb - About 1 hr to fix

    Method cache has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def cache(new_files)
          return if !new_files.is_a?(Array) && new_files.blank?
          old_uploaders = uploaders
          @uploaders = new_files.map do |new_file|
            handle_error do
    Severity: Minor
    Found in lib/carrierwave/mounter.rb - About 1 hr to fix

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

            def check_extension_allowlist!(new_file)
              allowlist = extension_allowlist
              if !allowlist && respond_to?(:extension_whitelist) && extension_whitelist
                ActiveSupport::Deprecation.warn "#extension_whitelist is deprecated, use #extension_allowlist instead." unless instance_variable_defined?(:@extension_whitelist_warned)
                @extension_whitelist_warned = true
      Severity: Minor
      Found in lib/carrierwave/uploader/extension_allowlist.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

      Avoid deeply nested control flow statements.
      Open

                        regional_host = 's3-accelerate.amazonaws.com' if @uploader.fog_aws_accelerate
      Severity: Major
      Found in lib/carrierwave/storage/fog.rb - About 45 mins to fix

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

                def authenticated_url(options = {})
                  if ['AWS', 'Google', 'Rackspace', 'OpenStack', 'AzureRM', 'Aliyun', 'backblaze'].include?(fog_provider)
                    # avoid a get by using local references
                    local_directory = connection.directories.new(:key => @uploader.fog_directory)
                    local_file = local_directory.files.new(:key => path)
        Severity: Minor
        Found in lib/carrierwave/storage/fog.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 check_content_type_allowlist! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def check_content_type_allowlist!(new_file)
                allowlist = content_type_allowlist
                if !allowlist && respond_to?(:content_type_whitelist) && content_type_whitelist
                  ActiveSupport::Deprecation.warn "#content_type_whitelist is deprecated, use #content_type_allowlist instead." unless instance_variable_defined?(:@content_type_whitelist_warned)
                  @content_type_whitelist_warned = true
        Severity: Minor
        Found in lib/carrierwave/uploader/content_type_allowlist.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

        Consider simplifying this complex logical expression.
        Open

              if file.is_a?(Hash)
                @file = file["tempfile"] || file[:tempfile]
                @original_filename = file["filename"] || file[:filename]
                @declared_content_type = file["content_type"] || file[:content_type] || file["type"] || file[:type]
              else
        Severity: Major
        Found in lib/carrierwave/sanitized_file.rb - About 40 mins to fix

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

              def resize_and_pad(width, height, background=nil, gravity='centre', alpha=nil, combine_options: {})
          Severity: Minor
          Found in lib/carrierwave/processing/vips.rb - About 35 mins to fix

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

                def resize_and_pad(width, height, background=:transparent, gravity='Center', combine_options: {}, &block)
            Severity: Minor
            Found in lib/carrierwave/processing/mini_magick.rb - About 35 mins to fix

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

                    def resize_and_pad(width, height, background=nil, gravity='centre', alpha=nil)
              Severity: Minor
              Found in lib/carrierwave/processing/vips.rb - About 35 mins to fix

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

                        def acl_header
                          case fog_provider
                          when 'AWS'
                            { 'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private' }
                          when "Google"
                Severity: Minor
                Found in lib/carrierwave/storage/fog.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 process_uri has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                      def process_uri(source)
                        uri = Addressable::URI.parse(source)
                        uri.host = uri.normalized_host
                        # Perform decode first, as the path is likely to be already encoded
                        uri.path = encode_path(decode_uri(uri.path)) if uri.path =~ CarrierWave::Utilities::Uri::PATH_UNSAFE
                Severity: Minor
                Found in lib/carrierwave/downloader/base.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 cache! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                      def cache!(new_file = file)
                        new_file = CarrierWave::SanitizedFile.new(new_file)
                        return if new_file.empty?
                
                        raise CarrierWave::FormNotMultipart if new_file.is_path? && ensure_multipart_form
                Severity: Minor
                Found in lib/carrierwave/uploader/cache.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 minimagick! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def minimagick!(block = nil)
                      builder = ImageProcessing::MiniMagick.source(current_path)
                      builder = yield(builder)
                
                      result = builder.call
                Severity: Minor
                Found in lib/carrierwave/processing/mini_magick.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 resolve_dimensions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def resolve_dimensions(*dimensions)
                      dimensions.map do |value|
                        next value unless value.instance_of?(Proc)
                        value.arity >= 1 ? value.call(self) : value.call
                      end
                Severity: Minor
                Found in lib/carrierwave/processing/vips.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 resolve_dimensions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def resolve_dimensions(*dimensions)
                      dimensions.map do |value|
                        next value unless value.instance_of?(Proc)
                        value.arity >= 1 ? value.call(self) : value.call
                      end
                Severity: Minor
                Found in lib/carrierwave/processing/mini_magick.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 store has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                        def store(new_file)
                          if new_file.is_a?(self.class)
                            new_file.copy_to(path)
                          else
                            fog_file = new_file.to_file
                Severity: Minor
                Found in lib/carrierwave/storage/fog.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

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

                      if File.extname(result.path) != File.extname(current_path)
                        move_to = current_path.chomp(File.extname(current_path)) + File.extname(result.path)
                        file.content_type = Marcel::Magic.by_path(move_to).try(:type)
                        file.move_to(move_to, permissions, directory_permissions)
                Severity: Minor
                Found in lib/carrierwave/processing/mini_magick.rb and 1 other location - About 35 mins to fix
                lib/carrierwave/processing/vips.rb on lines 260..263

                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

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

                      if File.extname(result.path) != File.extname(current_path)
                        move_to = current_path.chomp(File.extname(current_path)) + File.extname(result.path)
                        file.content_type = Marcel::Magic.by_path(move_to).try(:type)
                        file.move_to(move_to, permissions, directory_permissions)
                Severity: Minor
                Found in lib/carrierwave/processing/vips.rb and 1 other location - About 35 mins to fix
                lib/carrierwave/processing/mini_magick.rb on lines 308..311

                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 deduplicated_filename has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                      def deduplicated_filename
                        return unless filename
                        return filename unless @deduplication_index
                
                        parts = filename.split('.')
                Severity: Minor
                Found in lib/carrierwave/uploader/store.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

                Severity
                Category
                Status
                Source
                Language