OpenC3/cosmos

View on GitHub
openc3-cosmos-script-runner-api/app/models/running_script.rb

Summary

Maintainability
D
2 days
Test Coverage

Method spawn has 79 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.spawn(scope, name, suite_runner = nil, disconnect = false, environment = nil, user_full_name = nil, username = nil)
    if File.extname(name) == '.py'
      process_name = 'python'
      runner_path = File.join(RAILS_ROOT, 'scripts', 'run_script.py')
    else
Severity: Major
Found in openc3-cosmos-script-runner-api/app/models/running_script.rb - About 3 hrs to fix

    Method run_text has 75 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def run_text(text,
                   line_offset = 0,
                   text_binding = nil,
                   close_on_complete = false,
                   initial_filename: nil)
    Severity: Major
    Found in openc3-cosmos-script-runner-api/app/models/running_script.rb - About 3 hrs to fix

      Method instrument_script_implementation has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.instrument_script_implementation(ruby_lex_utils,
                                                  comments_removed_text,
                                                  _num_lines,
                                                  filename,
                                                  mark_private = false)
      Severity: Minor
      Found in openc3-cosmos-script-runner-api/app/models/running_script.rb - About 1 hr to fix

        Method initialize has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def initialize(id, scope, name, disconnect)
            @@instance = self
            @id = id
            @@id = id
            @scope = scope
        Severity: Minor
        Found in openc3-cosmos-script-runner-api/app/models/running_script.rb - About 1 hr to fix

          Method handle_output_io has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def handle_output_io(filename = @current_filename, line_number = @current_line_number)
              @output_time = Time.now.sys
              if @output_io.string[-1..-1] == "\n"
                time_formatted = Time.now.sys.formatted
                color = 'BLACK'
          Severity: Minor
          Found in openc3-cosmos-script-runner-api/app/models/running_script.rb - About 1 hr to fix

            Method parse_options has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def parse_options(options)
                settings = {}
                if options.include?('manual')
                  settings['Manual'] = true
                  $manual = true
            Severity: Minor
            Found in openc3-cosmos-script-runner-api/app/models/running_script.rb - About 1 hr to fix

              Method mark_stopped has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def mark_stopped
                  @state = :stopped
                  OpenC3::Store.publish([SCRIPT_API, "running-script-channel:#{@id}"].compact.join(":"), JSON.generate({ type: :line, filename: @current_filename, line_no: @current_line_number, state: @state }))
                  if OpenC3::SuiteRunner.suite_results
                    OpenC3::SuiteRunner.suite_results.complete
              Severity: Minor
              Found in openc3-cosmos-script-runner-api/app/models/running_script.rb - About 1 hr to fix

                Method debug has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def debug(debug_text)
                    handle_output_io()
                    if not running?
                      # Capture STDOUT and STDERR
                      $stdout.add_stream(@output_io)
                Severity: Minor
                Found in openc3-cosmos-script-runner-api/app/models/running_script.rb - About 1 hr to fix

                  Method spawn has 7 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    def self.spawn(scope, name, suite_runner = nil, disconnect = false, environment = nil, user_full_name = nil, username = nil)
                  Severity: Major
                  Found in openc3-cosmos-script-runner-api/app/models/running_script.rb - About 50 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                    if input == 'REJECTED'
                                      raise "Critical Cmd Rejected"
                                    end
                    Severity: Major
                    Found in openc3-cosmos-script-runner-api/app/models/running_script.rb - About 45 mins to fix

                      Method instrument_script_implementation has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                        def self.instrument_script_implementation(ruby_lex_utils,
                                                                  comments_removed_text,
                                                                  _num_lines,
                                                                  filename,
                                                                  mark_private = false)
                      Severity: Minor
                      Found in openc3-cosmos-script-runner-api/app/models/running_script.rb - About 35 mins to fix

                        Identical blocks of code found in 2 locations. Consider refactoring.
                        Open

                              auth = OpenC3::OpenC3KeycloakAuthentication.new(ENV['OPENC3_KEYCLOAK_URL'])
                              valid_token = auth.get_token_from_refresh_token(model.offline_access_token)
                              if valid_token
                                process.environment['OPENC3_API_TOKEN'] = model.offline_access_token
                              else
                        Severity: Minor
                        Found in openc3-cosmos-script-runner-api/app/models/running_script.rb and 1 other location - About 25 mins to fix
                        openc3-cosmos-script-runner-api/app/models/script.rb on lines 104..111

                        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 29.

                        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

                        Identical blocks of code found in 2 locations. Consider refactoring.
                        Open

                                OpenC3::Store.publish([SCRIPT_API, "running-script-channel:#{RunningScript.instance.id}"].compact.join(":"), JSON.generate({ type: :line, filename: RunningScript.instance.current_filename, line_no: RunningScript.instance.current_line_number, state: :waiting }))
                        Severity: Minor
                        Found in openc3-cosmos-script-runner-api/app/models/running_script.rb and 1 other location - About 20 mins to fix
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 165..165

                        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 28.

                        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

                        Identical blocks of code found in 2 locations. Consider refactoring.
                        Open

                                      OpenC3::Store.publish([SCRIPT_API, "running-script-channel:#{RunningScript.instance.id}"].compact.join(":"), JSON.generate({ type: :line, filename: RunningScript.instance.current_filename, line_no: RunningScript.instance.current_line_number, state: :waiting }))
                        Severity: Minor
                        Found in openc3-cosmos-script-runner-api/app/models/running_script.rb and 1 other location - About 20 mins to fix
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 155..155

                        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 28.

                        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

                        Similar blocks of code found in 6 locations. Consider refactoring.
                        Open

                          def mark_paused
                            @state = :paused
                            OpenC3::Store.publish([SCRIPT_API, "running-script-channel:#{@id}"].compact.join(":"), JSON.generate({ type: :line, filename: @current_filename, line_no: @current_line_number, state: @state }))
                        Severity: Minor
                        Found in openc3-cosmos-script-runner-api/app/models/running_script.rb and 5 other locations - About 15 mins to fix
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1025..1027
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1035..1037
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1040..1042
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1045..1047
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1097..1099

                        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 26.

                        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

                        Similar blocks of code found in 6 locations. Consider refactoring.
                        Open

                          def mark_error
                            @state = :error
                            OpenC3::Store.publish([SCRIPT_API, "running-script-channel:#{@id}"].compact.join(":"), JSON.generate({ type: :line, filename: @current_filename, line_no: @current_line_number, state: @state }))
                        Severity: Minor
                        Found in openc3-cosmos-script-runner-api/app/models/running_script.rb and 5 other locations - About 15 mins to fix
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1025..1027
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1030..1032
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1035..1037
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1045..1047
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1097..1099

                        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 26.

                        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

                        Similar blocks of code found in 6 locations. Consider refactoring.
                        Open

                          def mark_breakpoint
                            @state = :breakpoint
                            OpenC3::Store.publish([SCRIPT_API, "running-script-channel:#{@id}"].compact.join(":"), JSON.generate({ type: :line, filename: @current_filename, line_no: @current_line_number, state: @state }))
                        Severity: Minor
                        Found in openc3-cosmos-script-runner-api/app/models/running_script.rb and 5 other locations - About 15 mins to fix
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1025..1027
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1030..1032
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1035..1037
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1040..1042
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1045..1047

                        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 26.

                        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

                        Similar blocks of code found in 6 locations. Consider refactoring.
                        Open

                          def mark_running
                            @state = :running
                            OpenC3::Store.publish([SCRIPT_API, "running-script-channel:#{@id}"].compact.join(":"), JSON.generate({ type: :line, filename: @current_filename, line_no: @current_line_number, state: @state }))
                        Severity: Minor
                        Found in openc3-cosmos-script-runner-api/app/models/running_script.rb and 5 other locations - About 15 mins to fix
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1030..1032
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1035..1037
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1040..1042
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1045..1047
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1097..1099

                        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 26.

                        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

                        Similar blocks of code found in 6 locations. Consider refactoring.
                        Open

                          def mark_waiting
                            @state = :waiting
                            OpenC3::Store.publish([SCRIPT_API, "running-script-channel:#{@id}"].compact.join(":"), JSON.generate({ type: :line, filename: @current_filename, line_no: @current_line_number, state: @state }))
                        Severity: Minor
                        Found in openc3-cosmos-script-runner-api/app/models/running_script.rb and 5 other locations - About 15 mins to fix
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1025..1027
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1030..1032
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1040..1042
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1045..1047
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1097..1099

                        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 26.

                        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

                        Similar blocks of code found in 6 locations. Consider refactoring.
                        Open

                          def mark_fatal
                            @state = :fatal
                            OpenC3::Store.publish([SCRIPT_API, "running-script-channel:#{@id}"].compact.join(":"), JSON.generate({ type: :line, filename: @current_filename, line_no: @current_line_number, state: @state }))
                        Severity: Minor
                        Found in openc3-cosmos-script-runner-api/app/models/running_script.rb and 5 other locations - About 15 mins to fix
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1025..1027
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1030..1032
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1035..1037
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1040..1042
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 1097..1099

                        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 26.

                        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

                        Identical blocks of code found in 2 locations. Consider refactoring.
                        Open

                                  OpenC3::Store.publish([SCRIPT_API, "running-script-channel:#{RunningScript.instance.id}"].compact.join(":"), JSON.generate({ type: :file, filename: procedure_name, text: text.to_utf8, breakpoints: breakpoints }))
                        Severity: Minor
                        Found in openc3-cosmos-script-runner-api/app/models/running_script.rb and 1 other location - About 15 mins to fix
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 107..107

                        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 25.

                        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

                        Identical blocks of code found in 2 locations. Consider refactoring.
                        Open

                                  OpenC3::Store.publish([SCRIPT_API, "running-script-channel:#{RunningScript.instance.id}"].compact.join(":"), JSON.generate({ type: :file, filename: procedure_name, text: text.to_utf8, breakpoints: breakpoints }))
                        Severity: Minor
                        Found in openc3-cosmos-script-runner-api/app/models/running_script.rb and 1 other location - About 15 mins to fix
                        openc3-cosmos-script-runner-api/app/models/running_script.rb on lines 112..112

                        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 25.

                        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

                        There are no issues that match your filters.

                        Category
                        Status