File nexpose_raw_document.rb
has 553 lines of code (exceeds 250 allowed). Consider refactoring. Open
require "rex/parser/nokogiri_doc_mixin"
require "date"
module Rex
module Parser
Method report_vuln
has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring. Open
def report_vuln(&block)
return unless in_tag("VulnerabilityDefinitions")
return unless @report_data[:vuln]
return unless @report_data[:vuln][:matches].kind_of? Array
- 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
Method report_test
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
def report_test
return unless in_tag("nodes")
return unless in_tag("node")
return unless @state[:test]
- 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
Class NexposeRawDocument
has 31 methods (exceeds 20 allowed). Consider refactoring. Open
load_nokogiri && class NexposeRawDocument < Nokogiri::XML::SAX::Document
include NokogiriDocMixin
attr_reader :tests
Method collect_service_data
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
def collect_service_data
return unless in_tag("node")
return unless in_tag("endpoint")
port_hash = {}
@report_data[:ports] ||= []
- 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
Method report_host
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def report_host(&block)
if host_is_okay
db.emit(:address,@report_data[:host],&block) if block
device_id = @report_data[:nx_device_id]
- 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
Method end_element
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
def end_element(name=nil)
block = @block
case name
when "node" # Wrap it up
collect_host_data
Method report_test
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
def report_test
return unless in_tag("nodes")
return unless in_tag("node")
return unless @state[:test]
Method collect_formatted_content
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def collect_formatted_content(name)
stack = nil
prefix = ""
if in_tag("solution")
- 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
Method record_service_test
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def record_service_test(attrs)
return unless in_tag("nodes")
return unless in_tag("node")
return unless in_tag("service")
return unless in_tag("tests")
- 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
Method start_element
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
def start_element(name=nil,attrs=[])
attrs = normalize_attrs(attrs)
block = @block
@state[:current_tag][name] = true
case name
Method report_vuln
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
def report_vuln(&block)
return unless in_tag("VulnerabilityDefinitions")
return unless @report_data[:vuln]
return unless @report_data[:vuln][:matches].kind_of? Array
Method record_host_test
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def record_host_test(attrs)
return unless in_tag("nodes")
return unless in_tag("node")
return if in_tag("service")
return unless in_tag("tests")
- 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
Method collect_formatted_content
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def collect_formatted_content(name)
stack = nil
prefix = ""
if in_tag("solution")
Method collect_service_data
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def collect_service_data
return unless in_tag("node")
return unless in_tag("endpoint")
port_hash = {}
@report_data[:ports] ||= []
Method record_formatted_content
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def record_formatted_content(name, eattrs)
attrs = attr_hash(eattrs)
stack = nil
if in_tag("solution")
- 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
Method record_formatted_content
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def record_formatted_content(name, eattrs)
attrs = attr_hash(eattrs)
stack = nil
if in_tag("solution")
Method collect_host_data
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def collect_host_data
return unless in_tag("node")
@report_data[:host] = @state[:address]
@report_data[:state] = Msf::HostState::Alive
@report_data[:name] = @state[:hostname] if @state[:hostname]
- 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
Method collect_tag
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def collect_tag
return unless in_tag("tag")
return unless in_tag("tags")
return unless in_tag("vulnerability")
return unless @state[:vuln]
- 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
Method record_service_fingerprint
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def record_service_fingerprint(attrs)
return unless in_tag("nodes")
return unless in_tag("node")
return unless in_tag("service")
return unless in_tag("fingerprint")
- 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
Method report_fingerprint
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def report_fingerprint(host_object)
return unless host_object.kind_of? ::Mdm::Host
return unless @report_data[:os].kind_of? Hash
note = {
:workspace => host_object.workspace,
- 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
Method record_host
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def record_host(attrs)
return unless in_tag("nodes")
host_attrs = attr_hash(attrs)
if host_attrs["status"] == "alive"
@state[:host_is_alive] = true
- 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
Method collect_reference
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def collect_reference
return unless in_tag("references")
return unless in_tag("vulnerability")
return unless @state[:vuln]
@state[:ref][:value] = @text.to_s.strip
- 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
Method record_os_fingerprint
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def record_os_fingerprint(attrs)
return unless in_tag("nodes")
return unless in_tag("fingerprints")
return unless in_tag("node")
return if in_tag("service")
- 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
Avoid too many return
statements within this method. Open
return unless actually_vulnerable(test)
Avoid too many return
statements within this method. Open
return unless actually_vulnerable(test)
Method record_service_info
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def record_service_info(attrs)
return unless in_tag("nodes")
return unless in_tag("node")
return unless in_tag("service")
@state[:service].merge! attr_hash(attrs)
- 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
Method collect_vuln_solution
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def collect_vuln_solution
return unless in_tag("solution")
return unless in_tag("vulnerability")
return unless @state[:vuln]
@report_data[:vuln_solution] = clean_formatted_text( @report_data[:vuln_solution_stack].join.strip )
- 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
Method collect_vuln_info
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def collect_vuln_info
return unless in_tag("VulnerabilityDefinitions")
return unless in_tag("vulnerability")
return unless @state[:vuln]
vuln = @state[:vuln]
- 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
Method record_service
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def record_service(attrs)
return unless in_tag("nodes")
return unless in_tag("node")
return unless in_tag("endpoint")
@state[:service] = attr_hash(attrs)
- 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
Method collect_vuln_description
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def collect_vuln_description
return unless in_tag("description")
return unless in_tag("vulnerability")
return unless @state[:vuln]
@report_data[:vuln_description] = clean_formatted_text( @report_data[:vuln_description_stack].join.strip )
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
def report_services(host_object)
return unless host_object.kind_of? ::Mdm::Host
return unless @report_data[:ports]
return if @report_data[:ports].empty?
reported = []
- Read upRead up
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 37.
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