mikevallano/tmdb-moviequeue

View on GitHub
app/services/movie_data_service.rb

Summary

Maintainability
C
1 day
Test Coverage

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

    def update_movie(movie)
      # I'm not sure why this method uses HTTParty instead
      tmdb_id = movie.tmdb_id.to_s
      movie_url = "#{Tmdb::Client::BASE_URL}/movie/#{tmdb_id}?api_key=#{Tmdb::Client::API_KEY}&append_to_response=trailers,credits,releases"
      api_result = begin
Severity: Minor
Found in app/services/movie_data_service.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 get_common_movies_between_multiple_actors has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def get_common_movies_between_multiple_actors(actor_names: nil, paginate_actor_names: nil, page: nil, sort_by: nil)
      names = actor_names.uniq.reject { |name| name == '' }.compact.presence || paginate_actor_names.presence.split(';')
      return if names.blank?

      not_found_messages = []
Severity: Minor
Found in app/services/movie_data_service.rb - About 1 hr to fix

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

        def update_movie(movie)
          # I'm not sure why this method uses HTTParty instead
          tmdb_id = movie.tmdb_id.to_s
          movie_url = "#{Tmdb::Client::BASE_URL}/movie/#{tmdb_id}?api_key=#{Tmdb::Client::API_KEY}&append_to_response=trailers,credits,releases"
          api_result = begin
    Severity: Minor
    Found in app/services/movie_data_service.rb - About 1 hr to fix

      Method get_advanced_movie_search_results has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def get_advanced_movie_search_results(params)
            searched_terms = SearchParamParser.parse_movie_params_for_display(params)
            data = if params[:actor_name].present?
             person_id = Tmdb::Client.request(:person_search, query: params[:actor_name])&.dig(:results)&.first&.dig(:id)
             return OpenStruct.new(not_found_message: "No results for actor '#{params[:actor_name]}'.") if person_id.blank?
      Severity: Minor
      Found in app/services/movie_data_service.rb - About 1 hr to fix

        Method get_common_movies_between_multiple_actors has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_common_movies_between_multiple_actors(actor_names: nil, paginate_actor_names: nil, page: nil, sort_by: nil)
              names = actor_names.uniq.reject { |name| name == '' }.compact.presence || paginate_actor_names.presence.split(';')
              return if names.blank?
        
              not_found_messages = []
        Severity: Minor
        Found in app/services/movie_data_service.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 get_movies_for_actor has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def get_movies_for_actor(actor_name:, page:, sort_by:)
              person_data = Tmdb::Client.request(:person_search, query: actor_name)[:results]&.first
        
              if person_data.blank?
                return OpenStruct.new(
        Severity: Minor
        Found in app/services/movie_data_service.rb - About 1 hr to fix

          Method get_advanced_movie_search_results has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_advanced_movie_search_results(params)
                searched_terms = SearchParamParser.parse_movie_params_for_display(params)
                data = if params[:actor_name].present?
                 person_id = Tmdb::Client.request(:person_search, query: params[:actor_name])&.dig(:results)&.first&.dig(:id)
                 return OpenStruct.new(not_found_message: "No results for actor '#{params[:actor_name]}'.") if person_id.blank?
          Severity: Minor
          Found in app/services/movie_data_service.rb - 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

          Method get_movies_for_actor has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_movies_for_actor(actor_name:, page:, sort_by:)
                person_data = Tmdb::Client.request(:person_search, query: actor_name)[:results]&.first
          
                if person_data.blank?
                  return OpenStruct.new(
          Severity: Minor
          Found in app/services/movie_data_service.rb - About 35 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