padrino/padrino-framework

View on GitHub

Showing 211 of 211 total issues

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

        langs.each do |lang|
          filename   = "#{Padrino.root}/app/locale/models/#{m}/#{lang}.yml"
          columns    = klass.keys.values.map(&:name).reject { |name| name =~ /id/i }
          # If the lang file already exist we need to check it
          if File.exist?(filename)
Severity: Major
Found in padrino-gen/lib/padrino-gen/padrino-tasks/mongomapper.rb and 1 other location - About 3 hrs to fix
padrino-gen/lib/padrino-gen/padrino-tasks/mongoid.rb on lines 188..207

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

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

        langs.each do |lang|
          filename   = "#{Padrino.root}/app/locale/models/#{m}/#{lang}.yml"
          columns    = klass.fields.values.map(&:name).reject { |name| name =~ /id/i }
          # If the lang file already exist we need to check it.
          if File.exist?(filename)
Severity: Major
Found in padrino-gen/lib/padrino-gen/padrino-tasks/mongoid.rb and 1 other location - About 3 hrs to fix
padrino-gen/lib/padrino-gen/padrino-tasks/mongomapper.rb on lines 28..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 132.

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

      def setup_components
        self.destination_root = options[:root]
        if in_app_root?
          @_components = options.class.new options.select{ |key,_| self.class.component_types.include?(key.to_sym) }
          @app_name = (options[:app] || "App").gsub(/\W/, '_').camelize
Severity: Minor
Found in padrino-gen/lib/padrino-gen/generators/component.rb - About 3 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

Consider simplifying this complex logical expression.
Open

if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
  # Fixes for Yardoc YRI Building
  begin
    require 'active_record'
    require 'active_record/schema'
Severity: Critical
Found in padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb - About 3 hrs to fix

    Method output_migration_file has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

            def output_migration_file(filename, name, columns, options={})
              if behavior == :revoke
                remove_migration(name)
              else
                return if migration_exist?(filename)
    Severity: Minor
    Found in padrino-gen/lib/padrino-gen/generators/components/actions.rb - About 3 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 build_uri_query has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def build_uri_query(object, namespace = nil)
          case object
          when Hash
            object.map do |key, value|
              next if value == {} || value == []
    Severity: Minor
    Found in padrino-support/lib/padrino-support/utils.rb - About 3 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_db has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.create_db(adapter, user, password, host, database, charset, collation)
            case adapter
              when 'postgres'
                environment = {}
                environment['PGPASSWORD'] = password unless password.nil? || password.empty?
    Severity: Minor
    Found in padrino-gen/lib/padrino-gen/padrino-tasks/sql-helpers.rb - About 3 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 route has 76 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def route(verb, path, *args, &block)
            options = case args.size
              when 2
                args.last.merge(:map => args.first)
              when 1
    Severity: Major
    Found in padrino-core/lib/padrino-core/application/routing.rb - About 3 hrs to fix

      Class Message has 26 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class Message # @private
          include Sinatra::Templates
          include Padrino::Rendering if defined?(Padrino::Rendering)
          include Padrino::Helpers::RenderHelpers if defined? Padrino::Helpers::RenderHelpers
          attr_reader :template_cache
      Severity: Minor
      Found in padrino-mailer/lib/padrino-mailer/ext.rb - About 3 hrs to fix

        Class Storage has 25 methods (exceeds 20 allowed). Consider refactoring.
        Open

            class Storage
              include Enumerable
        
              # @private
              def initialize(session=nil)
        Severity: Minor
        Found in padrino-core/lib/padrino-core/application/flash.rb - About 2 hrs to fix

          File tooltip.js has 281 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          /* ========================================================================
           * Bootstrap: tooltip.js v3.1.0
           * http://getbootstrap.com/javascript/#tooltip
           * Inspired by the original jQuery.tipsy by Jason Frame
           * ========================================================================

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

                def self.setup!
                  config_level = (PADRINO_LOG_LEVEL || Padrino.env || :test).to_sym # need this for PADRINO_LOG_LEVEL
                  config = Config[config_level]
            
                  unless config
            Severity: Minor
            Found in padrino-core/lib/padrino-core/logger.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 drop_db has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
            Open

                  def self.drop_db(adapter, user, password, host, database)
                    case adapter
                      when 'postgres'
                        environment = {}
                        environment['PGPASSWORD'] = password unless password.nil? || password.empty?
            Severity: Minor
            Found in padrino-gen/lib/padrino-gen/padrino-tasks/sql-helpers.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 invoke_route has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
            Open

                  def invoke_route(route, params, first_time)
                    @_response_buffer = nil
                    @route = request.route_obj = route
                    captured_params = captures_from_params(params)
            
            
            Severity: Minor
            Found in padrino-core/lib/padrino-core/application/routing.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 render_like_sinatra has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
            Open

                  def render_like_sinatra(engine, data, options={}, locals={}, &block)
                    # merge app-level options
                    engine_options = settings.respond_to?(engine) ? settings.send(engine) : {}
                    options = engine_options.merge(options)
            
            
            Severity: Minor
            Found in padrino-helpers/lib/padrino/rendering.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 dispatch! has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
            Open

                  def dispatch!
                    @params = defined?(Sinatra::IndifferentHash) ? Sinatra::IndifferentHash[@request.params] : indifferent_params(@request.params)
                    force_encoding(@params)
                    invoke do
                      static! if settings.static? && (request.get? || request.head?)
            Severity: Minor
            Found in padrino-core/lib/padrino-core/application/routing.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

            File rendering.rb has 259 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            require 'padrino/core_ext/output_safety'
            require 'padrino-support'
            require 'pathname'
            
            module Padrino
            Severity: Minor
            Found in padrino-helpers/lib/padrino/rendering.rb - About 2 hrs to fix

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

                class Logger
                  ##
                  # Ruby (standard) logger levels:
                  #
                  # :fatal:: An not handleable error that results in a program crash
              Severity: Minor
              Found in padrino-core/lib/padrino-core/logger.rb - About 2 hrs to fix

                Method parse_route has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def parse_route(path, options, verb)
                        path = path.dup if path.kind_of?(String)
                        route_options = {}
                
                        if options[:params] == true
                Severity: Major
                Found in padrino-core/lib/padrino-core/application/routing.rb - About 2 hrs to fix

                  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

                  Severity
                  Category
                  Status
                  Source
                  Language