core/domain/exp_services.py

Summary

Maintainability
F
2 wks
Test Coverage

File exp_services.py has 3210 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# coding: utf-8
#
# Copyright 2014 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Severity: Major
Found in core/domain/exp_services.py - About 1 wk to fix

    Function apply_change_list has a Cognitive Complexity of 80 (exceeds 5 allowed). Consider refactoring.
    Open

    def apply_change_list(
        exploration_id: str, change_list: Sequence[exp_domain.ExplorationChange]
    ) -> exp_domain.Exploration:
        """Applies a changelist to a pristine exploration and returns the result.
    
    
    Severity: Minor
    Found in core/domain/exp_services.py - About 1 day 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

    Function validate_exploration_for_story has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
    Open

    def validate_exploration_for_story(
        exp: exp_domain.Exploration, strict: bool
    ) -> List[str]:
        """Validates an exploration with story validations.
    
    
    Severity: Minor
    Found in core/domain/exp_services.py - About 1 day 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

    Function regenerate_missing_stats_for_exploration has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

    def regenerate_missing_stats_for_exploration(
        exp_id: str
    ) -> Tuple[List[str], List[str], int, int]:
        """Regenerates missing ExplorationStats models and entries for all
        corresponding states in an exploration.
    Severity: Minor
    Found in core/domain/exp_services.py - About 7 hrs 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

    Function update_states_version_history has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def update_states_version_history(
        states_version_history: Dict[str, state_domain.StateVersionHistory],
        change_list: Sequence[exp_domain.ExplorationChange],
        old_states_dict: Dict[str, state_domain.StateDict],
        new_states_dict: Dict[str, state_domain.StateDict],
    Severity: Minor
    Found in core/domain/exp_services.py - About 3 hrs 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

    Function compute_models_to_put_when_saving_new_exp_version has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def compute_models_to_put_when_saving_new_exp_version(
        committer_id: str,
        exploration_id: str,
        change_list: Optional[Sequence[exp_domain.ExplorationChange]],
        commit_message: Optional[str],
    Severity: Minor
    Found in core/domain/exp_services.py - About 2 hrs 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

    Function get_exp_with_draft_applied has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_exp_with_draft_applied(
        exp_id: str, user_id: str
    ) -> Optional[exp_domain.Exploration]:
        """If a draft exists for the given user and exploration,
        apply it to the exploration.
    Severity: Minor
    Found in core/domain/exp_services.py - About 2 hrs 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

    Function sync_logged_out_learner_progress_with_logged_in_progress has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def sync_logged_out_learner_progress_with_logged_in_progress(
        user_id: str, exploration_id: str, unique_progress_url_id: str
    ) -> None:
    
        """Syncs logged out and logged in learner's checkpoints progress."""
    Severity: Minor
    Found in core/domain/exp_services.py - 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

    Function compute_models_to_put_when_saving_new_exp_version has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def compute_models_to_put_when_saving_new_exp_version(
        committer_id: str,
        exploration_id: str,
        change_list: Optional[Sequence[exp_domain.ExplorationChange]],
        commit_message: Optional[str],
    Severity: Minor
    Found in core/domain/exp_services.py - About 1 hr to fix

      Function get_exploration_ids_matching_query has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_exploration_ids_matching_query(
          query_string: str,
          categories: List[str],
          language_codes: List[str],
          offset: Optional[int] = None
      Severity: Minor
      Found in core/domain/exp_services.py - 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

      Function compute_exploration_contributors_summary has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def compute_exploration_contributors_summary(
          exploration_id: str
      ) -> Dict[str, int]:
          """Returns a dict whose keys are user_ids and whose values are
          the number of (non-revert) commits made to the given exploration
      Severity: Minor
      Found in core/domain/exp_services.py - 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

      Function get_user_exploration_data has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_user_exploration_data(
          user_id: str,
          exploration_id: str,
          apply_draft: bool = False,
          version: Optional[int] = None
      Severity: Minor
      Found in core/domain/exp_services.py - 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

      Function rollback_exploration_to_safe_state has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def rollback_exploration_to_safe_state(exp_id: str) -> int:
          """Rolls back exploration to the latest state where related metadata
          models are valid.
      
          Args:
      Severity: Minor
      Found in core/domain/exp_services.py - 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

      Function update_logged_out_user_progress has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def update_logged_out_user_progress(
          exploration_id: str,
          unique_progress_url_id: str,
          state_name: str,
          exp_version: int,
      Severity: Minor
      Found in core/domain/exp_services.py - About 55 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

      Avoid deeply nested control flow statements.
      Open

                              for audio_metadata in language_codes.values():
                                  audio_metadata['duration_secs'] = (
                                      float(audio_metadata['duration_secs'])
                                  )
                          recorded_voiceovers = (
      Severity: Major
      Found in core/domain/exp_services.py - About 45 mins to fix

        Function update_metadata_version_history has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def update_metadata_version_history(
        Severity: Minor
        Found in core/domain/exp_services.py - About 45 mins to fix

          Function update_states_version_history has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def update_states_version_history(
          Severity: Minor
          Found in core/domain/exp_services.py - About 45 mins to fix

            Function _compute_models_for_updating_exploration has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            def _compute_models_for_updating_exploration(
                committer_id: str,
                exploration: exp_domain.Exploration,
                commit_message: Optional[str],
                change_list: Sequence[exp_domain.ExplorationChange]
            Severity: Minor
            Found in core/domain/exp_services.py - About 45 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

            Avoid deeply nested control flow statements.
            Open

                                    if state.interaction.id is None:
                                        raise Exception(
                                            'solution cannot exist with None '
                                            'interaction id.'
                                        )
            Severity: Major
            Found in core/domain/exp_services.py - About 45 mins to fix

              Function _create_exploration has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              def _create_exploration(
                  committer_id: str,
                  exploration: exp_domain.Exploration,
                  commit_message: str,
                  commit_cmds: List[exp_domain.ExplorationChange]
              Severity: Minor
              Found in core/domain/exp_services.py - About 45 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

              Function create_or_update_draft has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              def create_or_update_draft(
              Severity: Minor
              Found in core/domain/exp_services.py - About 45 mins to fix

                Function update_exploration has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                def update_exploration(
                Severity: Minor
                Found in core/domain/exp_services.py - About 35 mins to fix

                  Function save_new_exploration_from_yaml_and_assets has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  def save_new_exploration_from_yaml_and_assets(
                  Severity: Minor
                  Found in core/domain/exp_services.py - About 35 mins to fix

                    Function compute_models_to_put_when_saving_new_exp_version has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                    def compute_models_to_put_when_saving_new_exp_version(
                    Severity: Minor
                    Found in core/domain/exp_services.py - About 35 mins to fix

                      Function get_updated_version_history_model has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      def get_updated_version_history_model(
                      Severity: Minor
                      Found in core/domain/exp_services.py - About 35 mins to fix

                        Function export_to_zip_file has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                        def export_to_zip_file(
                            exploration_id: str, version: Optional[int] = None
                        ) -> io.BytesIO:
                            """Returns a ZIP archive of the exploration.
                        
                        
                        Severity: Minor
                        Found in core/domain/exp_services.py - 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

                        There are no issues that match your filters.

                        Category
                        Status