OpenC3/cosmos

View on GitHub

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
Severity: Major
Found in openc3/lib/openc3/api/tlm_api.rb and 1 other location - About 1 hr to fix
openc3/lib/openc3/api/cmd_api.rb on lines 415..431

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

Further Reading

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
    Severity: Minor
    Found in openc3/lib/openc3/packets/packet.rb - About 1 hr to fix

      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
      Severity: Minor
      Found in openc3/lib/openc3/script/api_shared.rb - About 1 hr to fix

        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'))
        Severity: Minor
        Found in openc3/lib/openc3/system/system_config.rb - About 1 hr to fix

          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
          Severity: Minor
          Found in openc3/lib/openc3/models/activity_model.rb - About 1 hr to fix

            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,
            Severity: Minor
            Found in openc3/lib/openc3/models/target_model.rb - About 1 hr to fix

              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']]
              Severity: Minor
              Found in openc3/lib/openc3/packets/parsers/xtce_parser.rb - About 1 hr to fix

                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
                Severity: Minor
                Found in openc3/lib/openc3/packets/parsers/xtce_converter.rb - About 1 hr to fix

                  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
                  
                  
                  Severity: Minor
                  Found in openc3/lib/openc3/core_ext/io.rb - About 1 hr to fix

                    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
                    Severity: Minor
                    Found in openc3/lib/openc3/core_ext/time.rb - About 1 hr to fix

                      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,
                      Severity: Minor
                      Found in openc3/lib/openc3/logs/log_writer.rb - About 1 hr to fix

                        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
                        Severity: Minor
                        Found in openc3/lib/openc3/streams/tcpip_client_stream.rb - About 1 hr to fix

                          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
                            Severity: Minor
                            Found in openc3/lib/openc3/packets/limits.rb - About 1 hr to fix

                              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 = []
                              Severity: Minor
                              Found in openc3/lib/openc3/interfaces/interface.rb - About 1 hr to fix

                                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,
                                Severity: Minor
                                Found in openc3/lib/openc3/interfaces/udp_interface.rb - About 1 hr to fix

                                  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
                                  Severity: Minor
                                  Found in openc3/lib/openc3/utilities/crc.rb - About 1 hr to fix

                                    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 = []
                                      Severity: Minor
                                      Found in openc3-cosmos-cmd-tlm-api/app/controllers/storage_controller.rb - About 1 hr to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language