Showing 214 of 214 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.fields.values.map(&:name).reject { |name| name =~ /id/i }
# If the lang file already exist we need to check it.
if File.exist?(filename)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
- Read upRead up
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'
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)
- Read upRead up
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 == []
- Read upRead up
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?
- Read upRead up
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
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
Class Storage
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class Storage
include Enumerable
# @private
def initialize(session=nil)
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
- Read upRead up
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?
- Read upRead up
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)
- Read upRead up
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?)
- Read upRead up
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)
- Read upRead up
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
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
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
Method render
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def render(engine, file=nil, options={}, locals=nil, &block)
options.delete(:layout)
engine, file = file, engine if file.nil?
template_engine = engine ? ::Tilt[engine] : ::Tilt.default_mapping[file]
fail "Engine #{engine.inspect} is not registered with Tilt" unless template_engine
- Read upRead up
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"