Showing 52 of 52 total issues
Complex method describe(Qrinator)::describe(GET /*)::describe#QR generation (51.7) Open
describe 'QR generation' do
let(:path) { '/some/desired/path.html' }
let(:png) { instance_double('ChunkyPNG::Image') }
let(:qrcoder) { instance_double('RQRCode::QRCode', to_img: png) }
let(:payload) { base_url + path }
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(Qrinator)::describe(internals)::describe#download headers (48.0) Open
describe 'download headers' do
subject(:headers) { qrinator.download_headers }
it { is_expected.to match(a_hash_including('Content-Type' => 'application/octet-stream')) }
it { is_expected.to match(a_hash_including('Pragma' => 'public')) }
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(Qrinator)::describe(GET /*)::describe(QR generation)::it#composites the logo (35.6) Open
it 'composites the logo' do
expect(qrinator).to receive(:logo).and_return('the_logo')
expect(png).to receive(:compose).with('the_logo', size / 3, size / 3).and_return(png)
server.get(path)
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(Qrinator)::describe(GET /*)::describe(QR generation)::describe(with redis)::describe#when cached (33.6) Open
describe 'when cached' do
before do
allow(redis).to receive(:exists).with(path).and_return(true)
allow(redis).to receive(:get).with(path).and_return(png_blob)
end
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(Qrinator)::describe(GET /*)::describe(logo)::describe(with redis)::describe#when cached (33.6) Open
describe 'when cached' do
before do
allow(redis).to receive(:exists).with(logo_url).and_return(true)
allow(redis).to receive(:get).with(logo_url).and_return(logo_blob)
end
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(Qrinator)::describe(GET /*)::describe(logo)::it#returns the resized logo (30.8) Open
it 'returns the resized logo' do
resized_logo = instance_double('ChunkyPNG::Image')
expect(logo_png).to receive(:resize).with(size / 3, size / 3).and_return(resized_logo)
expect(qrinator.logo).to eq resized_logo
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(Qrinator)::describe(GET /*)::describe(QR generation)::describe(with redis)::describe(when cached)::it#returns the cached image in the body (27.5) Open
it 'returns the cached image in the body' do
allow(redis).to receive(:get).with(path).and_return('cached qr code')
response = server.get(path)
expect(response.body).to eq 'cached qr code'
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Qrinator has at least 5 instance variables Open
class Qrinator
- Read upRead up
- Exclude checks
Too Many Instance Variables
is a special case of LargeClass
.
Example
Given this configuration
TooManyInstanceVariables:
max_instance_variables: 3
and this code:
class TooManyInstanceVariables
def initialize
@arg_1 = :dummy
@arg_2 = :dummy
@arg_3 = :dummy
@arg_4 = :dummy
end
end
Reek would emit the following warning:
test.rb -- 5 warnings:
[1]:TooManyInstanceVariables has at least 4 instance variables (TooManyInstanceVariables)
Complex method describe(Qrinator)::describe(GET /*)::describe(logo)::describe(with redis)::describe(when cached)::it#uses the cached logo (24.5) Open
it 'uses the cached logo' do
allow(redis).to receive(:get).with(logo_url).and_return('cached_logo')
expect(qrinator.raw_logo_data).to eq 'cached_logo'
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(Qrinator)::describe(GET /*)::describe(logo)::it#converts the raw data to a png (23.7) Open
it 'converts the raw data to a png' do
expect(ChunkyPNG::Image).to receive(:from_blob).with(logo_blob).and_return(logo_png)
expect(qrinator.logo).to be logo_png
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Qrinator#initialize calls 'T.let(@size / 3, Integer)' 2 times Open
@offset = T.let(@size / 3, Integer)
@inset = T.let(@size / 3, Integer)
- 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.
Qrinator#redis_params calls 'ENV['REDISCLOUD_URL']' 2 times Open
return {} if ENV['REDISCLOUD_URL'].nil?
uri = URI.parse(T.must(ENV['REDISCLOUD_URL']))
- 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.
Qrinator#redis_set_unless_exists calls 'T.must(redis)' 3 times Open
if T.must(redis).exists(key)
T.must(redis).get(key)
else
result = yield(key)
T.must(redis).set(key, result)
- 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.
Qrinator#initialize calls '@size / 3' 2 times Open
@offset = T.let(@size / 3, Integer)
@inset = T.let(@size / 3, Integer)
- 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.
Complex method describe(Qrinator)::describe(GET /*)::describe(QR generation)::describe(with redis)::describe(when not cached)::it#generates with the full desired url (22.5) Open
it 'generates with the full desired url' do
expect(RQRCode::QRCode).to receive(:new).with(payload, a_hash_including).and_return(qrcoder)
server.get(path)
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(Qrinator)::describe(GET /*)::describe(QR generation)::describe(with redis)::describe(when cached)::it#fetches the result in the cache (22.3) Open
it 'fetches the result in the cache' do
expect(redis).to receive(:get).with(path).and_return(png_blob)
server.get(path)
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(Qrinator)::describe(GET /*)::describe(QR generation)::it#resizes the image (21.9) Open
it 'resizes the image' do
expect(png).to receive(:resize).with(size, size).and_return(png)
server.get(path)
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(Qrinator)::describe(GET /*)::describe#logo (21.8) Open
describe 'logo' do
let(:logo_blob) { 'logo_png' }
let!(:stub_get) { stub_request(:get, logo_url).to_return(body: logo_blob) }
let(:logo_png) { instance_double('ChunkyPNG::Image') }
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Qrinator#redis_params performs a nil-check Open
return {} if ENV['REDISCLOUD_URL'].nil?
- Read upRead up
- Exclude checks
A NilCheck
is a type check. Failures of NilCheck
violate the "tell, don't ask" principle.
Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.
Example
Given
class Klass
def nil_checker(argument)
if argument.nil?
puts "argument isn't nil!"
end
end
end
Reek would emit the following warning:
test.rb -- 1 warning:
[3]:Klass#nil_checker performs a nil-check. (NilCheck)
Qrinator#redis_params doesn't depend on instance state (maybe move it to another class?) Open
def redis_params
- Read upRead up
- Exclude checks
A Utility Function is any instance method that has no dependency on the state of the instance.