File capture.rb
has 518 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'uri'
require 'rex/sync/event'
require 'fileutils'
module Msf
Method listeners_start
has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring. Open
def listeners_start(args)
config = parse_start_args(args)
if config[:show_help]
help('start')
return
- 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 listeners_start
has 145 lines of code (exceeds 25 allowed). Consider refactoring. Open
def listeners_start(args)
config = parse_start_args(args)
if config[:show_help]
help('start')
return
Class ConsoleCommandDispatcher
has 31 methods (exceeds 20 allowed). Consider refactoring. Open
class ConsoleCommandDispatcher
include Msf::Ui::Console::CommandDispatcher
class CaptureJobListener
def initialize(name, done_event, dispatcher)
Method parse_start_args
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def parse_start_args(args)
config_file = File.join(Msf::Config.config_directory, 'capture_config.yaml')
# See if there was a config file set
@start_opt_parser.parse(args) do |opt, _idx, val|
case opt
Method listeners_stop
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def listeners_stop(args)
options = parse_stop_args(args)
if options[:show_help]
help('stop')
return
- 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 validate_params
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def validate_params(options)
unless options[:srvhost] && Rex::Socket.is_ip_addr?(options[:srvhost])
raise ArgumentError, 'Must provide a valid IP address to listen on'
end
# If we're running poisoning (which is disabled remotely, so excluding that situation),
- 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 transform_params
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def transform_params(options)
# If we've been given a specific IP to listen on, use that as our poisoning IP
if options[:spoof_ip].nil? && Rex::Socket.is_ip_addr?(options[:srvhost]) && Rex::Socket.addr_atoi(options[:srvhost]) != 0
options[:spoof_ip] = options[:srvhost]
end
- 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 cmd_captureg
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def cmd_captureg(*args)
# short circuit the whole deal if they need help
return help if args.empty?
return help if args.length == 1 && args.first =~ HELP_REGEX
return help(args.last) if args.length == 2 && args.first =~ HELP_REGEX
- 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 []
Avoid too many return
statements within this method. Open
return help
Avoid too many return
statements within this method. Open
return result
Avoid too many return
statements within this method. Open
return
Similar blocks of code found in 2 locations. Consider refactoring. Open
modules = {
# Capturing
'DRDA' => 'auxiliary/server/capture/drda',
'FTP' => 'auxiliary/server/capture/ftp',
'IMAP' => 'auxiliary/server/capture/imap',
- 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 44.
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