Method select
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def select(value = nil, from: nil, **options)
if has_css?('.pf-c-form__group', text: from, wait: 0)
within('.pf-c-form__group', text: from) do
if has_css?('select.pf-c-form-control', wait: 0)
super
- 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
CapybaraExtensions takes parameters ['locator', 'options'] to 3 methods Open
def find_field(locator, **options)
if has_css?('.pf-c-form__label', text: locator, wait: 0)
find('.pf-c-form__group', text: locator).find('input, textarea, select, .CodeMirror', **options)
else
super
- Read upRead up
- Exclude checks
In general, a Data Clump
occurs when the same two or three items frequently appear together in classes and parameter lists, or when a group of instance variable names start or end with similar substrings.
The recurrence of the items often means there is duplicate code spread around to handle them. There may be an abstraction missing from the code, making the system harder to understand.
Example
Given
class Dummy
def x(y1,y2); end
def y(y1,y2); end
def z(y1,y2); end
end
Reek would emit the following warning:
test.rb -- 1 warning:
[2, 3, 4]:Dummy takes parameters [y1, y2] to 3 methods (DataClump)
A possible way to fix this problem (quoting from Martin Fowler):
The first step is to replace data clumps with objects and use the objects whenever you see them. An immediate benefit is that you'll shrink some parameter lists. The interesting stuff happens as you begin to look for behavior to move into the new objects.