Showing 43 of 43 total issues
File process.rb
has 396 lines of code (exceeds 250 allowed). Consider refactoring. Open
gem 'state_machine'
require 'state_machine'
require 'daemons'
require 'bluepill/system'
Class Process
has 34 methods (exceeds 20 allowed). Consider refactoring. Open
class Process
CONFIGURABLE_ATTRIBUTES = [
:pre_start_command,
:start_command,
:stop_command,
Method validate_process!
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def validate_process!(process)
# validate uniqueness of group:process
process_key = [process.attributes[:group], process.name].join(':')
if @@process_keys.key?(process_key)
$stderr.print "Config Error: You have two entries for the process name '#{process.name}'"
- 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 execute_blocking
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def execute_blocking(cmd, options = {})
rd, wr = IO.pipe
child = Daemonize.safefork
if child
- 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 kill_previous_bluepill
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def kill_previous_bluepill
return unless File.exist?(pid_file)
previous_pid = File.read(pid_file).to_i
return unless System.pid_alive?(previous_pid)
::Process.kill(0, previous_pid)
- 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 stop_process
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def stop_process
if monitor_children
System.get_children(actual_pid).each do |child_pid|
ProcessJournal.append_pid_to_journal(name, child_pid)
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 status
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def status(process_name = nil)
lines = []
if process_name.nil?
prefix = name ? ' ' : ''
lines << "#{name}:" if name
- 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_process!
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
def validate_process!(process)
# validate uniqueness of group:process
process_key = [process.attributes[:group], process.name].join(':')
if @@process_keys.key?(process_key)
$stderr.print "Config Error: You have two entries for the process name '#{process.name}'"
Method execute_blocking
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
def execute_blocking(cmd, options = {})
rd, wr = IO.pipe
child = Daemonize.safefork
if child
Method kill_all_pids_from_journal
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def kill_all_pids_from_journal(journal_name)
filename = pid_journal_filename(journal_name)
j = pid_journal(filename)
if !j.empty?
acquire_atomic_fs_lock(filename) do
- 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 kill_all_pgids_from_journal
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def kill_all_pgids_from_journal(journal_name)
filename = pgid_journal_filename(journal_name)
j = pgid_journal(filename)
if !j.empty?
acquire_atomic_fs_lock(filename) do
- 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 stop_process
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
def stop_process
if monitor_children
System.get_children(actual_pid).each do |child_pid|
ProcessJournal.append_pid_to_journal(name, child_pid)
end
Method daemonize
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def daemonize(cmd, options = {})
rd, wr = IO.pipe
child = Daemonize.safefork
if child
- 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_listener
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def start_listener
@listener_thread.kill if @listener_thread
@listener_thread = Thread.new do
loop do
begin
- 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 drop_privileges
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def drop_privileges(uid, gid, supplementary_groups)
return unless ::Process::Sys.geteuid.zero?
uid_num = Etc.getpwnam(uid).uid if uid
gid_num = Etc.getgrnam(gid).gid if gid
supplementary_groups ||= []
- 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 handle_command
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def handle_command(application, command, *args)
case command.to_sym
when :status
puts send_to_daemon(application, :status, *args)
when :quit
Method start_process
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def start_process
ProcessJournal.kill_all_from_journal(name) # be sure nothing else is running from previous runs
pre_start_process
logger.warning "Executing start command: #{start_command}"
if daemonize?
- 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 kill_all_pgids_from_journal
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def kill_all_pgids_from_journal(journal_name)
filename = pgid_journal_filename(journal_name)
j = pgid_journal(filename)
if !j.empty?
acquire_atomic_fs_lock(filename) do
Method kill_all_pids_from_journal
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def kill_all_pids_from_journal(journal_name)
filename = pid_journal_filename(journal_name)
j = pid_journal(filename)
if !j.empty?
acquire_atomic_fs_lock(filename) do
Similar blocks of code found in 2 locations. Consider refactoring. Open
acquire_atomic_fs_lock(filename) do
if pgid_journal(filename).include?(pgid)
logger.debug("Skipping duplicate pgid #{pgid} already in journal #{journal_name}")
else
logger.debug("Saving pgid #{pgid} to process journal #{journal_name}")
- 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 52.
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