padrino/padrino-framework

View on GitHub

Showing 214 of 214 total issues

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

      def filter_params!(params, allowed_params)
        params.each do |key,value|
          type = allowed_params[key]
          next if value.kind_of?(Array) && type
          case
Severity: Minor
Found in padrino-core/lib/padrino-core/application/params_protection.rb - About 2 hrs 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 require_dependencies has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    def require_dependencies(*paths)
      options = { :cyclic => true }.update(paths.last.is_a?(Hash) ? paths.pop : {})

      files = paths.flatten.flat_map{ |path| Dir.glob(path).sort_by{ |filename| filename.count('/') } }.uniq

Severity: Minor
Found in padrino-core/lib/padrino-core/loader.rb - About 2 hrs 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 create_app has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

      def create_app
        self.destination_root = options[:root]
        underscore_name = name.gsub(/\W/, '_')
        @app_folder = underscore_name.underscore
        @app_name   = underscore_name.camelize
Severity: Minor
Found in padrino-gen/lib/padrino-gen/generators/app.rb - About 2 hrs 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

Function show has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  Tooltip.prototype.show = function () {
    var e = $.Event('show.bs.' + this.type)

    if (this.hasContent() && this.enabled) {
      this.$element.trigger(e)

    Method provides_format has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

          def provides_format(*types)
            mime_types = types.map{ |type| mime_type(CONTENT_TYPE_ALIASES[type] || type) }
            condition do
              return provides_format?(types, params[:format].to_sym) if params[:format]
    
    
    Severity: Minor
    Found in padrino-core/lib/padrino-core/application/routing.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 server_options has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

          def server_options(options)
            
              info = []
              server = Rack::Handler.get(options[:server]) || Rack::Handler.default(options)
              if server && server.respond_to?(:valid_options)
    Severity: Minor
    Found in padrino-core/lib/padrino-core/cli/launcher.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 render has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def render(engine=nil, data=nil, options={}, locals={}, &block)
          locals = @_locals || {} if !options[:locals] && locals.empty?
          @template_cache.clear if settings.reload_templates?
    
          engine ||= message_name
    Severity: Minor
    Found in padrino-mailer/lib/padrino-mailer/ext.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 route! has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

          def route!(base = settings, pass_block = nil)
            Thread.current['padrino.instance'] = self
            first_time = true
    
            routes = base.compiled_router.call(@request) do |route, params|
    Severity: Minor
    Found in padrino-core/lib/padrino-core/application/routing.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 create_database has 47 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def create_database(config)
          begin
            if config[:adapter] =~ /sqlite/
              if File.exist?(config[:database])
                $stderr.puts "#{config[:database]} already exists."
    Severity: Minor
    Found in padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb - About 1 hr to fix

      Function slide has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        Carousel.prototype.slide = function (type, next) {
          var $active   = this.$element.find('.item.active')
          var $next     = next || $active[type]()
          var isCycling = this.interval
          var direction = type == 'next' ? 'left' : 'right'

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

              def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, options = {})
                from_time = from_time.to_time if from_time.respond_to?(:to_time)
                to_time = to_time.to_time if to_time.respond_to?(:to_time)
                distance_in_minutes = (((to_time.to_i - from_time.to_i).abs)/60).round
                distance_in_seconds = ((to_time.to_i - from_time.to_i).abs).round
        Severity: Minor
        Found in padrino-helpers/lib/padrino-helpers/format_helpers.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 partial has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

              def partial(template, options={}, &block)
                options = { :layout => false }.update(options)
                explicit_engine = options.delete(:engine)
        
                path, _, name = template.to_s.rpartition(File::SEPARATOR)
        Severity: Minor
        Found in padrino-helpers/lib/padrino-helpers/render_helpers.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 number_to_human_size has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

              def number_to_human_size(number, *args)
                return nil if number.nil?
        
                options = args.last.is_a?(Hash) ? Utils.symbolize_keys(args.pop) : {}
        
        
        Severity: Minor
        Found in padrino-helpers/lib/padrino-helpers/number_helpers.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 convert_ids has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            def convert_ids(obj)
              if obj.is_a?(String) && obj =~ /^[a-f0-9]{24}$/
                defined?(Moped) ? Moped::BSON::ObjectId.from_string(obj) : BSON::ObjectId(obj)
              elsif obj.is_a?(Array)
                obj.map do |v|
        Severity: Minor
        Found in padrino-gen/lib/padrino-gen/padrino-tasks/mongoid.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

          $(window).on('load', function () {
            $('[data-ride="carousel"]').each(function () {
              var $carousel = $(this)
              $carousel.carousel($carousel.data())
            })
        padrino-admin/lib/padrino-admin/generators/templates/assets/javascripts/bootstrap/scrollspy.js on lines 146..151

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

        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

          $(window).on('load', function () {
            $('[data-spy="scroll"]').each(function () {
              var $spy = $(this)
              $spy.scrollspy($spy.data())
            })
        padrino-admin/lib/padrino-admin/generators/templates/assets/javascripts/bootstrap/carousel.js on lines 198..203

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

        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

        Consider simplifying this complex logical expression.
        Open

        if PadrinoTasks.load?(:datamapper, defined?(DataMapper))
          namespace :dm do
            namespace :auto do
              desc "Perform auto migration (reset your db data)"
              task :migrate => :environment do
        Severity: Critical
        Found in padrino-gen/lib/padrino-gen/padrino-tasks/datamapper.rb - About 1 hr to fix

          Method distance_of_time_in_words has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, options = {})
                  from_time = from_time.to_time if from_time.respond_to?(:to_time)
                  to_time = to_time.to_time if to_time.respond_to?(:to_time)
                  distance_in_minutes = (((to_time.to_i - from_time.to_i).abs)/60).round
                  distance_in_seconds = ((to_time.to_i - from_time.to_i).abs).round
          Severity: Minor
          Found in padrino-helpers/lib/padrino-helpers/format_helpers.rb - About 1 hr to fix

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

                  def setup_test_files
                    if options[:tiny] && @_components[:test] != :none
                      test_component = @_components[:test]
                      test_component = "rspec" if test_component == "cucumber"
                      uppercase_test_component = test_component.upcase
            Severity: Minor
            Found in padrino-gen/lib/padrino-gen/generators/project.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 setup_orm has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            def setup_orm
              dm = DM
              db = @project_name.underscore
              %w(
                dm-core
              Severity
              Category
              Status
              Source
              Language