Showing 123 of 123 total issues
Business::BR::CPF#validate calls 'cpf.length' 2 times Open
return false unless cpf.length == 11 || cpf.length == 14
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Business::BR::CEP::Providers has no descriptive comment Open
class Providers
- Read upRead up
- Exclude checks
Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.
Example
Given
class Dummy
# Do things...
end
Reek would emit the following warning:
test.rb -- 1 warning:
[1]:Dummy has no descriptive comment (IrresponsibleModule)
Fixing this is simple - just an explaining comment:
# The Dummy class is responsible for ...
class Dummy
# Do things...
end
Business::BR::CPF declares the class variable '@@black_list' Open
@@black_list = %w[
00000000000
11111111111
22222222222
33333333333
- Read upRead up
- Exclude checks
Class variables form part of the global runtime state, and as such make it easy for one part of the system to accidentally or inadvertently depend on another part of the system. So the system becomes more prone to problems where changing something over here breaks something over there. In particular, class variables can make it hard to set up tests (because the context of the test includes all global state).
For a detailed explanation, check out this article
Example
Given
class Dummy
@@class_variable = :whatever
end
Reek would emit the following warning:
reek test.rb
test.rb -- 1 warning:
[2]:Dummy declares the class variable @@class_variable (ClassVariable)
Getting rid of the smell
You can use class-instance variable to mitigate the problem (as also suggested in the linked article above):
class Dummy
@class_variable = :whatever
end
Business::BR::CNPJ#validate calls 'cnpj.length' 2 times Open
return false unless cnpj.length == 14 || cnpj.length == 18
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Business::BR::CPF#validate calls 'cpf[i]' 2 times Open
first_num += (10 - i) * cpf[i].to_i
end
10.times do |i|
second_num += (11 - i) * cpf[i].to_i
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Business::BR::CNPJ#validate calls 'cnpj[i].to_i' 2 times Open
first_num += numbers[i + 1] * cnpj[i].to_i
end
13.times do |i|
second_num += numbers[i] * cnpj[i].to_i
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Business::BR::CEP::Providers::Base has no descriptive comment Open
class Base
- Read upRead up
- Exclude checks
Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.
Example
Given
class Dummy
# Do things...
end
Reek would emit the following warning:
test.rb -- 1 warning:
[1]:Dummy has no descriptive comment (IrresponsibleModule)
Fixing this is simple - just an explaining comment:
# The Dummy class is responsible for ...
class Dummy
# Do things...
end
Business::BR::CEP#validate calls 'cep.length' 2 times Open
return false unless cep.length == 8 || cep.length == 9
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Business::BR::CEP::Providers::Postmon has no descriptive comment Open
class Postmon < Base
- Read upRead up
- Exclude checks
Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.
Example
Given
class Dummy
# Do things...
end
Reek would emit the following warning:
test.rb -- 1 warning:
[1]:Dummy has no descriptive comment (IrresponsibleModule)
Fixing this is simple - just an explaining comment:
# The Dummy class is responsible for ...
class Dummy
# Do things...
end
Business::BR::CNPJ has no descriptive comment Open
class CNPJ
- Read upRead up
- Exclude checks
Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.
Example
Given
class Dummy
# Do things...
end
Reek would emit the following warning:
test.rb -- 1 warning:
[1]:Dummy has no descriptive comment (IrresponsibleModule)
Fixing this is simple - just an explaining comment:
# The Dummy class is responsible for ...
class Dummy
# Do things...
end
Avoid too many return
statements within this method. Open
return false unless cpf[9..10] == "#{first_num}#{second_num}"
Business::BR::CNPJ#normalize doesn't depend on instance state (maybe move it to another class?) Open
def normalize(cnpj)
- Read upRead up
- Exclude checks
A Utility Function is any instance method that has no dependency on the state of the instance.
Block has too many lines. [26/25] Open
Gem::Specification.new do |spec|
spec.name = 'business-br'
spec.license = 'MIT'
spec.version = Business::BR::VERSION
spec.authors = ['Daniel Vinciguerra']
- Read upRead up
- Exclude checks
This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.
Business::BR::CEP::Providers::Base#zipcode is a writable attribute Open
attr_accessor :zipcode
- Read upRead up
- Exclude checks
A class that publishes a setter for an instance variable invites client classes to become too intimate with its inner workings, and in particular with its representation of state.
The same holds to a lesser extent for getters, but Reek doesn't flag those.
Example
Given:
class Klass
attr_accessor :dummy
end
Reek would emit the following warning:
reek test.rb
test.rb -- 1 warning:
[2]:Klass declares the writable attribute dummy (Attribute)
Business::BR::CEP#normalize doesn't depend on instance state (maybe move it to another class?) Open
def normalize(cep)
- Read upRead up
- Exclude checks
A Utility Function is any instance method that has no dependency on the state of the instance.
Business::BR::CPF#format doesn't depend on instance state (maybe move it to another class?) Open
def format(cpf)
- Read upRead up
- Exclude checks
A Utility Function is any instance method that has no dependency on the state of the instance.
Business::BR::CNPJ#format doesn't depend on instance state (maybe move it to another class?) Open
def format(cnpj)
- Read upRead up
- Exclude checks
A Utility Function is any instance method that has no dependency on the state of the instance.
Business::BR::CPF#normalize doesn't depend on instance state (maybe move it to another class?) Open
def normalize(cpf)
- Read upRead up
- Exclude checks
A Utility Function is any instance method that has no dependency on the state of the instance.
Business::BR::CEP::Providers::Base#decode_json doesn't depend on instance state (maybe move it to another class?) Open
def decode_json(str)
- Read upRead up
- Exclude checks
A Utility Function is any instance method that has no dependency on the state of the instance.
Business::BR::CEP#validate doesn't depend on instance state (maybe move it to another class?) Open
def validate(cep)
- Read upRead up
- Exclude checks
A Utility Function is any instance method that has no dependency on the state of the instance.