Method attributes_data
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def attributes_data
attributes = %i[cloud_object_store_containers miq_templates vms security_groups cloud_networks cloud_subnets network_ports cloud_volumes]
attr_icon = {
:cloud_object_store_containers => 'ff ff-cloud-object-store',
- Create a ticketCreate a ticket
Similar blocks of code found in 2 locations. Consider refactoring. Open
def attributes_data
attributes = %i[cloud_object_store_containers miq_templates vms security_groups cloud_networks cloud_subnets network_ports cloud_volumes]
attr_icon = {
:cloud_object_store_containers => 'ff ff-cloud-object-store',
- Read upRead up
- Create a ticketCreate a ticket
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 80.
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
Unused method argument - controller
. If it's necessary, use _
or _controller
as an argument name to indicate that it won't be used. If it's unnecessary, remove it. Open
def initialize(tenant, controller, klass)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for unused method arguments.
Example:
# bad
def some_method(used, unused, _unused_but_allowed)
puts used
end
# good
def some_method(used, _unused, _unused_but_allowed)
puts used
end
Example: AllowUnusedKeywordArguments: false (default)
# bad
def do_something(used, unused: 42)
used
end
Example: AllowUnusedKeywordArguments: true
# good
def do_something(used, unused: 42)
used
end
Example: IgnoreEmptyMethods: true (default)
# good
def do_something(unused)
end
Example: IgnoreEmptyMethods: false
# bad
def do_something(unused)
end
Example: IgnoreNotImplementedMethods: true (default)
# good
def do_something(unused)
raise NotImplementedError
end
def do_something_else(unused)
fail "TODO"
end
Example: IgnoreNotImplementedMethods: false
# bad
def do_something(unused)
raise NotImplementedError
end
def do_something_else(unused)
fail "TODO"
end
Unused method argument - klass
. If it's necessary, use _
or _klass
as an argument name to indicate that it won't be used. If it's unnecessary, remove it. Open
def initialize(tenant, controller, klass)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for unused method arguments.
Example:
# bad
def some_method(used, unused, _unused_but_allowed)
puts used
end
# good
def some_method(used, _unused, _unused_but_allowed)
puts used
end
Example: AllowUnusedKeywordArguments: false (default)
# bad
def do_something(used, unused: 42)
used
end
Example: AllowUnusedKeywordArguments: true
# good
def do_something(used, unused: 42)
used
end
Example: IgnoreEmptyMethods: true (default)
# good
def do_something(unused)
end
Example: IgnoreEmptyMethods: false
# bad
def do_something(unused)
end
Example: IgnoreNotImplementedMethods: true (default)
# good
def do_something(unused)
raise NotImplementedError
end
def do_something_else(unused)
fail "TODO"
end
Example: IgnoreNotImplementedMethods: false
# bad
def do_something(unused)
raise NotImplementedError
end
def do_something_else(unused)
fail "TODO"
end
Call super
to initialize state of the parent class. Open
def initialize(tenant, controller, klass)
@record_id = tenant.id
@record = tenant
end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for the presence of constructors and lifecycle callbacks
without calls to super
.
This cop does not consider method_missing
(and respond_to_missing?
)
because in some cases it makes sense to overtake what is considered a
missing method. In other cases, the theoretical ideal handling could be
challenging or verbose for no actual gain.
Autocorrection is not supported because the position of super
cannot be
determined automatically.
Object
and BasicObject
are allowed by this cop because of their
stateless nature. However, sometimes you might want to allow other parent
classes from this cop, for example in the case of an abstract class that is
not meant to be called with super
. In those cases, you can use the
AllowedParentClasses
option to specify which classes should be allowed
in addition to Object
and BasicObject
.
Example:
# bad
class Employee < Person
def initialize(name, salary)
@salary = salary
end
end
# good
class Employee < Person
def initialize(name, salary)
super(name)
@salary = salary
end
end
# bad
Employee = Class.new(Person) do
def initialize(name, salary)
@salary = salary
end
end
# good
Employee = Class.new(Person) do
def initialize(name, salary)
super(name)
@salary = salary
end
end
# bad
class Parent
def self.inherited(base)
do_something
end
end
# good
class Parent
def self.inherited(base)
super
do_something
end
end
# good
class ClassWithNoParent
def initialize
do_something
end
end
Example: AllowedParentClasses: [MyAbstractClass]
# good
class MyConcreteClass < MyAbstractClass
def initialize
do_something
end
end