Showing 1,379 of 1,379 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
def _extract_target_packet_names(method_name, *args)
target_name = nil
packet_name = nil
case args.length
when 1
- 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 62.
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
Function convertToString
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
convertToString(value) {
var i = 0
var returnValue = ''
if (Object.prototype.toString.call(value).slice(8, -1) === 'Array') {
var arrayLength = value.length
Method write_item
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def write_item(item, value, value_type = :CONVERTED, buffer = @buffer)
case value_type
when :RAW
super(item, value, value_type, buffer)
when :CONVERTED
Method wait_tolerance
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def wait_tolerance(*args, type: :CONVERTED, quiet: false, scope: $openc3_scope, token: $openc3_token)
raise "Invalid type '#{type}' for wait_tolerance" unless %i(RAW CONVERTED).include?(type)
target_name, packet_name, item_name, expected_value, tolerance, timeout, polling_rate = _wait_tolerance_process_args(args)
start_time = Time.now.sys
Method save_configuration
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def save_configuration
configuration = find_configuration(@config.name)
configuration = File.join(@paths['SAVED_CONFIG'], File.build_timestamped_filename([@config.name], '.zip')) unless configuration
unless File.exist?(configuration)
configuration_tmp = File.join(@paths['SAVED_CONFIG'], File.build_timestamped_filename(['tmp_' + @config.name], '.zip.tmp'))
Method destroy
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.destroy(name:, scope:, score:, uuid: nil, recurring: nil)
result = 0
# Delete all recurring activities
if recurring
Method as_json
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def as_json(*_a)
{
'name' => @name,
'folder_name' => @folder_name,
'requires' => @requires,
Method get_object_types
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_object_types(element)
array_type = nil
if /Parameter/.match?(element.name)
# Look up the parameter and parameter type
parameter = @parameters[element['parameterRef']]
Method create_commands
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_commands(xml, commands, target_name)
return unless commands[target_name]
xml['xtce'].CommandMetaData do
xml['xtce'].ArgumentTypeSet do
Method fast_select
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def fast_select(read_sockets = nil, write_sockets = nil, error_array = nil, timeout = nil)
# Always try a zero timeout first
current_timeout = SELECT_BASE_TIMEOUT
total_timeout = 0.0
Method julian2mdy
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.julian2mdy(jdate)
z = (jdate + 0.5).to_i
w = ((z - 1867216.25) / 36524.25).to_i
x = w / 4
a = z + 1 + w - x
Method initialize
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(
remote_log_directory,
logging_enabled = true,
cycle_time = nil,
cycle_size = 1_000_000_000,
Method initialize
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(hostname, write_port, read_port, write_timeout, read_timeout, connect_timeout = 5.0)
@hostname = hostname
if @hostname.to_s.upcase == 'LOCALHOST'
@hostname = '127.0.0.1'
end
Method traefik
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def traefik
result = {}
result['http'] = {}
http = result['http']
http['routers'] = {}
Method set
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def set(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high, green_low = nil, green_high = nil, limits_set = :CUSTOM, persistence = nil, enabled = true)
packet = _get_packet(target_name, packet_name)
item = packet.get_item(item_name)
limits = item.limits
if limits_set
Method initialize
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize
@name = self.class.to_s.split("::")[-1] # Remove namespacing if present
@state = 'DISCONNECTED'
@target_names = []
@cmd_target_names = []
Method initialize
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(
hostname,
write_dest_port,
read_port,
write_src_port = nil,
Method initialize
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(poly, seed, xor, reflect)
@poly = poly
@seed = seed
@xor = xor
@reflect = reflect
Method next_packet_and_topic
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def next_packet_and_topic
next_time = nil
next_reader = nil
closed_readers = nil
@open_readers.each do |reader|
Method files
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def files
return unless authorization('system')
root = ENV[params[:root]] # Get the actual bucket / volume name
raise "Unknown bucket / volume #{params[:root]}" unless root
results = []