Class has too many lines. [155/100] Open
class Git < Base
include Coa::Constants
CREDENTIALS_AUTO_INIT_PATH = "#{SECRETS_REPO_DIR}/coa/config/credentials-auto-init.yml".freeze
GIT_CONFIG_PATH = "#{SECRETS_REPO_DIR}/coa/config/credentials-git-config.yml".freeze
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [21/10] Open
def generated_concouse_credentials(concourse_config)
bosh_config = bosh.config
concourse_pw = concourse_config.password
concourse_un = concourse_config.username
concourse_url = concourse_config.url
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [17/10] Open
def init_and_push(repo_path, repo_name)
logger.log_and_puts :debug, "Init #{repo_name} at <#{repo_path}>"
coa_submodule_path = "shared-files/cf-ops-automation-reference-dataset-submodule-sample"
Dir.chdir repo_path do
submodule_commit_reference = templates_coa_reference_dataset_submodule_sha1(coa_submodule_path, repo_path)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [17/10] Open
def push_cf_ops_automation
logger.log_and_puts :debug, "Setup cf_ops_automation push at <#{PROJECT_ROOT_DIR}>"
Dir.chdir PROJECT_ROOT_DIR do
remote_name = "remote-" + SecureRandom.hex
branch_name = "br-" + SecureRandom.hex
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for init_and_push is too high. [18.71/15] Open
def init_and_push(repo_path, repo_name)
logger.log_and_puts :debug, "Init #{repo_name} at <#{repo_path}>"
coa_submodule_path = "shared-files/cf-ops-automation-reference-dataset-submodule-sample"
Dir.chdir repo_path do
submodule_commit_reference = templates_coa_reference_dataset_submodule_sha1(coa_submodule_path, repo_path)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Assignment Branch Condition size for push_cf_ops_automation is too high. [18.49/15] Open
def push_cf_ops_automation
logger.log_and_puts :debug, "Setup cf_ops_automation push at <#{PROJECT_ROOT_DIR}>"
Dir.chdir PROJECT_ROOT_DIR do
remote_name = "remote-" + SecureRandom.hex
branch_name = "br-" + SecureRandom.hex
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Coa::EnvBootstrapper::Git#create_git_submodule_from_templates_repo is controlled by argument 'repo_path' Open
return unless repo_path == TEMPLATES_REPO_DIR
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Control Parameter
is a special case of Control Couple
Example
A simple example would be the "quoted" parameter in the following method:
def write(quoted)
if quoted
write_quoted @value
else
write_unquoted @value
end
end
Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".
Coa::EnvBootstrapper::Git#init_and_push has approx 16 statements Open
def init_and_push(repo_path, repo_name)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
Coa::EnvBootstrapper::Git#templates_coa_reference_dataset_submodule_sha1 is controlled by argument 'repo_path' Open
return unless repo_path == TEMPLATES_REPO_DIR
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Control Parameter
is a special case of Control Couple
Example
A simple example would be the "quoted" parameter in the following method:
def write(quoted)
if quoted
write_quoted @value
else
write_unquoted @value
end
end
Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".
Coa::EnvBootstrapper::Git has at least 19 methods Open
class Git < Base
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Too Many Methods
is a special case of LargeClass
.
Example
Given this configuration
TooManyMethods:
max_methods: 3
and this code:
class TooManyMethods
def one; end
def two; end
def three; end
def four; end
end
Reek would emit the following warning:
test.rb -- 1 warning:
[1]:TooManyMethods has at least 4 methods (TooManyMethods)
Coa::EnvBootstrapper::Git#push_cf_ops_automation has approx 10 statements Open
def push_cf_ops_automation
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
Method push_cf_ops_automation
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def push_cf_ops_automation
logger.log_and_puts :debug, "Setup cf_ops_automation push at <#{PROJECT_ROOT_DIR}>"
Dir.chdir PROJECT_ROOT_DIR do
remote_name = "remote-" + SecureRandom.hex
branch_name = "br-" + SecureRandom.hex
- Read upRead up
- Create a ticketCreate a ticket
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
Coa::EnvBootstrapper::Git#templates_coa_reference_dataset_submodule_sha1 has the name 'templates_coa_reference_dataset_submodule_sha1' Open
def templates_coa_reference_dataset_submodule_sha1(coa_submodule_path, repo_path)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
An Uncommunicative Method Name
is a method name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
Coa::EnvBootstrapper::Git#extract_submodule_commit_reference has the variable name 'commit_sha1' Open
commit_sha1, submodule_path, = line.split(' ')
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
An Uncommunicative Variable Name
is a variable name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
Operator =>
should be surrounded by a single space. Open
"concourse-audit-trail-uri" => "git://#{server_ip}/k8s-configs"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that operators have space around them, except for ** which should not have surrounding space.
Example:
# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b
# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b