cloudfoundry/cloud_controller_ng

View on GitHub
app/models/runtime/process_model.rb

Summary

Maintainability
D
2 days
Test Coverage

Class ProcessModel has 78 methods (exceeds 20 allowed). Consider refactoring.
Open

  class ProcessModel < Sequel::Model(:processes)
    include Serializer

    plugin :serialization
    plugin :after_initialize
Severity: Major
Found in app/models/runtime/process_model.rb - About 1 day to fix

    File process_model.rb has 456 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'cloud_controller/process_observer'
    require 'cloud_controller/database_uri_generator'
    require 'cloud_controller/errors/application_missing'
    require 'repositories/app_usage_event_repository'
    require 'presenters/v3/cache_key_presenter'
    Severity: Minor
    Found in app/models/runtime/process_model.rb - About 6 hrs to fix

      Method version_needs_to_be_updated? has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def version_needs_to_be_updated?
            # change version if:
            #
            # * transitioning to STARTED
            # * memory is changed
      Severity: Minor
      Found in app/models/runtime/process_model.rb - About 1 hr to fix

      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 open_ports has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def open_ports
            open_ports = ports || []
      
            if docker?
              has_mapping_without_port = route_mappings_dataset.where(app_port: ProcessModel::NO_APP_PORT_SPECIFIED).any?
      Severity: Minor
      Found in app/models/runtime/process_model.rb - About 1 hr to fix

      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 after_initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def after_initialize
            self.instances        ||= db_schema[:instances][:default].to_i
            self.memory           ||= Config.config.get(:default_app_memory)
            self.disk_quota       ||= Config.config.get(:default_app_disk_in_mb)
            self.file_descriptors ||= Config.config.get(:instance_file_descriptor_limit)
      Severity: Minor
      Found in app/models/runtime/process_model.rb - About 25 mins to fix

      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

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

            space_guids = Space.join(:spaces_developers, space_id: :id, user_id: user.id).select(:spaces__guid).
                          union(Space.join(:spaces_managers, space_id: :id, user_id: user.id).select(:spaces__guid)).
                          union(Space.join(:spaces_auditors, space_id: :id, user_id: user.id).select(:spaces__guid)).
                          union(Space.join(:organizations_managers, organization_id: :organization_id, user_id: user.id).select(:spaces__guid)).select(:guid)
      Severity: Minor
      Found in app/models/runtime/process_model.rb and 1 other location - About 1 hr to fix
      app/models/runtime/app_model.rb on lines 153..156

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

      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 3 locations. Consider refactoring.
      Open

          one_through_one :latest_droplet,
                          class: 'VCAP::CloudController::DropletModel',
                          join_table: AppModel.table_name,
                          left_primary_key: :app_guid, left_key: :guid,
                          right_primary_key: :app_guid, right_key: :guid,
      Severity: Minor
      Found in app/models/runtime/process_model.rb and 2 other locations - About 15 mins to fix
      app/models/runtime/process_model.rb on lines 62..69
      app/models/runtime/process_model.rb on lines 69..76

      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 3 locations. Consider refactoring.
      Open

          one_through_one :latest_package,
                          class: 'VCAP::CloudController::PackageModel',
                          join_table: AppModel.table_name,
                          left_primary_key: :app_guid, left_key: :guid,
                          right_primary_key: :app_guid, right_key: :guid,
      Severity: Minor
      Found in app/models/runtime/process_model.rb and 2 other locations - About 15 mins to fix
      app/models/runtime/process_model.rb on lines 69..76
      app/models/runtime/process_model.rb on lines 76..83

      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 3 locations. Consider refactoring.
      Open

          one_through_one :latest_build,
                          class: 'VCAP::CloudController::BuildModel',
                          join_table: AppModel.table_name,
                          left_primary_key: :app_guid, left_key: :guid,
                          right_primary_key: :app_guid, right_key: :guid,
      Severity: Minor
      Found in app/models/runtime/process_model.rb and 2 other locations - About 15 mins to fix
      app/models/runtime/process_model.rb on lines 62..69
      app/models/runtime/process_model.rb on lines 76..83

      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

      There are no issues that match your filters.

      Category
      Status