ndlib/sipity

View on GitHub
app/repositories/sipity/queries/processing_queries.rb

Summary

Maintainability
D
2 days
Test Coverage
A
100%

File processing_queries.rb has 569 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'active_support/core_ext/array/wrap'

module Sipity
  module Queries
    # Welcome intrepid developer. You have stumbled into some complex data
Severity: Major
Found in app/repositories/sipity/queries/processing_queries.rb - About 1 day to fix

Method scope_processing_entities_for_the_user_and_proxy_for_type has 77 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def scope_processing_entities_for_the_user_and_proxy_for_type(criteria:)
        proxy_for_type = PowerConverter.convert(criteria.proxy_for_type, to: :polymorphic_type)

        entities = Models::Processing::Entity.arel_table
        strategy_state_actions = Models::Processing::StrategyStateAction.arel_table
Severity: Major
Found in app/repositories/sipity/queries/processing_queries.rb - About 3 hrs to fix

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

      def scope_users_for_entity_and_roles(entity:, roles:)
        entity = Conversions::ConvertToProcessingEntity.call(entity)
        role_ids = Array.wrap(roles).map { |role| Conversions::ConvertToRole.call(role).id }
        group_polymorphic_type = PowerConverter.convert(Models::Group, to: :polymorphic_type)
        user_polymorphic_type = PowerConverter.convert(User, to: :polymorphic_type)
Severity: Minor
Found in app/repositories/sipity/queries/processing_queries.rb - About 1 hr to fix

Method scope_permitted_entity_strategy_actions_for_current_state has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def scope_permitted_entity_strategy_actions_for_current_state(user:, entity:)
        action_scope = scope_permitted_without_concern_for_repetition_entity_strategy_actions_for_current_state(user: user, entity: entity)

        entity = Conversions::ConvertToProcessingEntity.call(entity)
        actor = Conversions::ConvertToProcessingActor.call(user)
Severity: Minor
Found in app/repositories/sipity/queries/processing_queries.rb - About 1 hr to fix

Method scope_actors_associated_with_entity_and_role has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def scope_actors_associated_with_entity_and_role(entity:, role:)
        entity = Conversions::ConvertToProcessingEntity.call(entity)
        role = Conversions::ConvertToRole.call(role)
        strategy_roles = Models::Processing::StrategyRole.arel_table
        strategy_responsibilities = Models::Processing::StrategyResponsibility.arel_table
Severity: Minor
Found in app/repositories/sipity/queries/processing_queries.rb - About 1 hr to fix

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

      def collaborators_that_have_taken_the_action_on_the_entity(entity:, actions:)
        entity = Conversions::ConvertToProcessingEntity.call(entity)
        collaborators = Models::Collaborator.arel_table
        users = User.arel_table
        users_scope = users_that_have_taken_the_action_on_the_entity(entity: entity, actions: actions)
Severity: Minor
Found in app/repositories/sipity/queries/processing_queries.rb - About 1 hr to fix

Method scope_processing_entities_for_the_user_and_proxy_for_type has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def scope_processing_entities_for_the_user_and_proxy_for_type(criteria:)
        proxy_for_type = PowerConverter.convert(criteria.proxy_for_type, to: :polymorphic_type)

        entities = Models::Processing::Entity.arel_table
        strategy_state_actions = Models::Processing::StrategyStateAction.arel_table
Severity: Minor
Found in app/repositories/sipity/queries/processing_queries.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

        actors_select_manager = actors.project(
          :*,
          Arel.sql("'#{Models::Processing::Actor::ENTITY_LEVEL_ACTOR_PROCESSING_RELATIONSHIP}'").as('actor_processing_relationship')
        ).where(
          actors[:id].in(
Severity: Major
Found in app/repositories/sipity/queries/processing_queries.rb and 1 other location - About 1 hr to fix
app/repositories/sipity/queries/processing_queries.rb on lines 107..116

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

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

          actors.project(
            :*,
            Arel.sql("'#{Models::Processing::Actor::STRATEGY_LEVEL_ACTOR_PROCESSING_RELATIONSHIP}'").as('actor_processing_relationship')
          ).where(
            actors[:id].in(
Severity: Major
Found in app/repositories/sipity/queries/processing_queries.rb and 1 other location - About 1 hr to fix
app/repositories/sipity/queries/processing_queries.rb on lines 93..102

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

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

        completed_guarded_actions_subquery = action_prereqs.arel_table.project(
          action_prereqs.arel_table[:guarded_strategy_action_id]
        ).where(
          action_prereqs.arel_table[:prerequisite_strategy_action_id].in(
            actions_that_occurred.arel_table.project(actions_that_occurred.arel_table[:id]).
Severity: Minor
Found in app/repositories/sipity/queries/processing_queries.rb and 1 other location - About 15 mins to fix
app/repositories/sipity/queries/processing_queries.rb on lines 768..773

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

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

              permissions.arel_table.project(
                permissions.arel_table[:strategy_state_action_id]
              ).where(
                permissions.arel_table[:strategy_role_id].in(
                  role_scope.arel_table.project(role_scope.arel_table[:id]).where(
Severity: Minor
Found in app/repositories/sipity/queries/processing_queries.rb and 1 other location - About 15 mins to fix
app/repositories/sipity/queries/processing_queries.rb on lines 798..803

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