padrino/padrino-framework

View on GitHub
padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb

Summary

Maintainability
D
2 days
Test Coverage

Method create_database has a Cognitive Complexity of 46 (exceeds 5 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 7 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 activerecord.rb has 381 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

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

        Avoid deeply nested control flow statements.
        Open

                    $stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config[:charset]
        Severity: Major
        Found in padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb - About 45 mins to fix

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

            def migrate_as(type)
              version = env_migration_version
              fail "MIGRATION_VERSION is required" unless version
          
              if less_than_active_record_5_2?
          Severity: Minor
          Found in padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.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 move_as has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def move_as(type)
              step = ENV['STEP'] ? ENV['STEP'].to_i : 1
          
              if less_than_active_record_5_2?
                ActiveRecord::Migrator.send(type, 'db/migrate/', step)
          Severity: Minor
          Found in padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.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 drop_database has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def drop_database(config)
              case config[:adapter]
              when 'mysql', 'mysql2', 'em_mysql2', 'jdbcmysql'
                ActiveRecord::Base.establish_connection(config)
                ActiveRecord::Base.connection.drop_database config[:database]
          Severity: Minor
          Found in padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.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

                ActiveRecord::Migrator.run(type, "db/migrate/", version)
              elsif less_than_active_record_6_0?
                ActiveRecord::MigrationContext.new('db/migrate/').run(type, version)
              else
                ActiveRecord::MigrationContext.new('db/migrate/', ActiveRecord::SchemaMigration).run(type, version)
          Severity: Minor
          Found in padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb and 1 other location - About 15 mins to fix
          padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb on lines 397..402

          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

                ActiveRecord::Migrator.send(type, 'db/migrate/', step)
              elsif less_than_active_record_6_0?
                ActiveRecord::MigrationContext.new('db/migrate/').send(type, step)
              else
                ActiveRecord::MigrationContext.new('db/migrate/', ActiveRecord::SchemaMigration).send(type, step)
          Severity: Minor
          Found in padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb and 1 other location - About 15 mins to fix
          padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb on lines 383..388

          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

          There are no issues that match your filters.

          Category
          Status