carrierwaveuploader/carrierwave

View on GitHub

Showing 48 of 48 total issues

Method store has a Cognitive Complexity of 9 (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 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 resize_and_pad has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity)
      width = dimension_from width
      height = dimension_from height
      manipulate! do |img|
        img.resize_to_fit!(width, height)
Severity: Minor
Found in lib/carrierwave/processing/rmagick.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

Avoid deeply nested control flow statements.
Open

                  host   = case region
                           when DEFAULT_S3_REGION, ''
                             's3.amazonaws.com'
                           else
                             "s3.#{region}.amazonaws.com"
Severity: Major
Found in lib/carrierwave/storage/fog.rb - About 45 mins to fix

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

          def source_versions_of(requested_names)
            versions.inject([]) do |sources, (name, uploader)|
              next sources unless requested_names.include?(name)
              next sources unless source_name = uploader.class.version_options[:from_version]
    
    
    Severity: Minor
    Found in lib/carrierwave/uploader/versions.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

                      s3_subdomain = @uploader.fog_aws_accelerate ? "s3-accelerate" : "s3"
    Severity: Major
    Found in lib/carrierwave/storage/fog.rb - About 45 mins 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

      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

      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?(@uploader.fog_credentials[: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

      Consider simplifying this complex logical expression.
      Open

            if file.is_a?(Hash)
              @file = file["tempfile"] || file[:tempfile]
              @original_filename = file["filename"] || file[:filename]
              @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=nil, gravity='centre', alpha=nil)
          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 read has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def read
                    if @content
                      @content
                    elsif is_path?
                      File.open(@file, "rb") {|file| file.read}
              Severity: Minor
              Found in lib/carrierwave/sanitized_file.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 download has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                    def download(url, remote_headers = {})
                      @current_download_retry_count = 0
                      headers = remote_headers.
                        reverse_merge('User-Agent' => "CarrierWave/#{CarrierWave::VERSION}")
                      uri = process_uri(url.to_s)
              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 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

              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 307..310

              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 3 locations. Consider refactoring.
              Open

                    class IntegrityValidator < ::ActiveModel::EachValidator
              
                      def validate_each(record, attribute, value)
                        record.__send__("#{attribute}_integrity_errors").each do |e|
                          message = (e.message == e.class.to_s) ? :carrierwave_integrity_error : e.message
              Severity: Minor
              Found in lib/carrierwave/validations/active_model.rb and 2 other locations - About 25 mins to fix
              lib/carrierwave/validations/active_model.rb on lines 11..16
              lib/carrierwave/validations/active_model.rb on lines 31..36

              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 31.

              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