Showing 35 of 35 total issues
Method validate_proposal_after_save
has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring. Open
def validate_proposal_after_save proposal
validate_at_least_n_for_role proposal, "ceph-mon", 1
validate_count_as_odd_for_role proposal, "ceph-mon"
validate_at_least_n_for_role proposal, "ceph-osd", 2
- 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
Method apply_role_pre_chef_call
has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring. Open
def apply_role_pre_chef_call(old_role, role, all_nodes)
@logger.debug("ceph apply_role_pre_chef_call: entering #{all_nodes.inspect}")
monitors = role.override_attributes["ceph"]["elements"]["ceph-mon"] || []
osd_nodes = role.override_attributes["ceph"]["elements"]["ceph-osd"] || []
mds_nodes = role.override_attributes["ceph"]["elements"]["ceph-mds"] || []
- 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
File ceph_service.rb
has 314 lines of code (exceeds 250 allowed). Consider refactoring. Open
require "chef"
def mask_to_bits(mask)
octets = mask.split(".")
count = 0
- Create a ticketCreate a ticket
Method apply_role_pre_chef_call
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
def apply_role_pre_chef_call(old_role, role, all_nodes)
@logger.debug("ceph apply_role_pre_chef_call: entering #{all_nodes.inspect}")
monitors = role.override_attributes["ceph"]["elements"]["ceph-mon"] || []
osd_nodes = role.override_attributes["ceph"]["elements"]["ceph-osd"] || []
mds_nodes = role.override_attributes["ceph"]["elements"]["ceph-mds"] || []
- Create a ticketCreate a ticket
Method find_node_ip_in_network
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def find_node_ip_in_network(network, nodeish=nil)
nodeish = node unless nodeish
net = IPAddr.new(network)
nodeish["network"]["interfaces"].each do |iface|
if iface[1]["routes"].nil?
- 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
Method validate_proposal_after_save
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
def validate_proposal_after_save proposal
validate_at_least_n_for_role proposal, "ceph-mon", 1
validate_count_as_odd_for_role proposal, "ceph-mon"
validate_at_least_n_for_role proposal, "ceph-osd", 2
- Create a ticketCreate a ticket
Method mask_to_bits
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def mask_to_bits(mask)
octets = mask.split(".")
count = 0
octets.each do |octet|
break if octet == "0"
- 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
Method role_constraints
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
def role_constraints
{
"ceph-calamari" => {
"unique" => false,
"count" => 1,
- Create a ticketCreate a ticket
Method auth_set_key
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def auth_set_key(ceph_conf, admin_keyring, keyname, caps)
raise "No caps defined for ceph_client resource!" if caps.empty?
# try to add the key
caps_str = caps.map { |k, v| "#{k} '#{v}'" }.join(" ")
cmd = "ceph -k #{admin_keyring} -c #{ceph_conf} auth get-or-create #{keyname} #{caps_str}"
- 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
Method create_proposal
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_proposal
@logger.debug("Ceph create_proposal: entering")
base = super
if base["attributes"]["ceph"]["config"]["fsid"].empty?
- Create a ticketCreate a ticket
Method create_proposal
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def create_proposal
@logger.debug("Ceph create_proposal: entering")
base = super
if base["attributes"]["ceph"]["config"]["fsid"].empty?
- 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
Method get_ceph_client_name
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def get_ceph_client_name(cnode)
if cnode["ceph"] && cnode["ceph"]["client_network"]
net_name = cnode["ceph"]["client_network"]
elsif node["ceph"] && node["ceph"]["client_network"]
net_name = node["ceph"]["client_network"]
- 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
Method apply_role_post_chef_call
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def apply_role_post_chef_call(old_role, role, all_nodes)
@logger.debug("ceph apply_role_post_chef_call: entering #{all_nodes.inspect}")
calamari = role.override_attributes["ceph"]["elements"]["ceph-calamari"] || []
calamari.each do |n|
- 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
Method get_mon_addresses
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def get_mon_addresses()
mon_ips = []
node_name = get_ceph_client_name(node)
if File.exist?("/var/run/ceph/ceph-mon.#{node_name}.asok")
mon_ips = get_quorum_members_ips()
- 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
Method get_mon_nodes
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def get_mon_nodes(extra_search=nil)
if is_crowbar?
mon_roles = search(:role, "name:crowbar-* AND run_list_map:ceph-mon")
if not mon_roles.empty?
search_string = mon_roles.map { |role_object| "roles:"+role_object.name }.join(" OR ")
- 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
Avoid deeply nested control flow statements. Open
create_cmd = create_cmd + " #{journal_device}" if journal_device
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if ssd_partitions > partitions_per_ssd && ssd_devices[ssd_index+1]
ssd_partitions = 0
ssd_index = ssd_index + 1
end
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
case service_type
when "upstart"
service_name "ceph-osd-all-starter"
provider Chef::Provider::Service::Upstart
else
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
extra_options = "--mark-init systemd" if service_type == "systemd"
- Create a ticketCreate a ticket
Similar blocks of code found in 2 locations. Consider refactoring. Open
bash "convert signing ca certificate to nss db format" do
code <<-EOH
openssl x509 -in #{nss_dir}/keystone_ca.pem -pubkey | certutil -d #{nss_dir} -A -n ca -t 'TCu,Cu,Tuw'
chown #{node[:apache][:user]}:#{node[:apache][:group]} #{nss_dir}/*.db
EOH
- 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 35.
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