Showing 41 of 41 total issues
Method list_sort_handler
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def list_sort_handler(sort_by, member = nil)
@sort_by = sort_by
@member = member
if @member.present?
@user = User.find(@member)
- Read upRead up
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 list_sort_handler
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
def list_sort_handler(sort_by, member = nil)
@sort_by = sort_by
@member = member
if @member.present?
@user = User.find(@member)
Method get_providers
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_providers(tmdb_id:, title:, media_type:, media_format:, release_date: nil)
params = { tmdb_id: tmdb_id, media_type: media_type }
results = Tmdb::Client.request(:streaming_service_providers, params)&.dig(:results, :US)
parameterized_title = title.parameterize(separator: '+')
Similar blocks of code found in 2 locations. Consider refactoring. Open
def self.parse_result(result)
new(
directing: MovieCredits.parse(result[:crew].select { |crew| crew[:job] == 'Director' }),
editing: MovieCredits.parse(result[:crew].select { |crew| crew[:job] == 'Editor' }),
writing: MovieCredits.parse(result[:crew ].select { |crew| crew[:job] == 'Writer' }),
- Read upRead up
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 81.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
def self.parse_result(result)
new(
directing: TVCredits.parse(result[:crew].select { |crew| crew[:job] == 'Director' }),
editing: TVCredits.parse(result[:crew].select { |crew| crew[:job] == 'Editor' }),
writing: TVCredits.parse(result[:crew ].select { |crew| crew[:job] == 'Writer' }),
- Read upRead up
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 81.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Method build_url_for_movie_discover_search
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def build_url_for_movie_discover_search(params)
page = params[:page].presence || 1
sort_by = params[:sort_by].presence || 'popularity'
api_path = "/discover/movie?api_key=#{ENV['tmdb_api_key']}&certification_country=US"
api_path += "&with_people=#{params[:people]}" if params[:people].present?
- Read upRead up
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 create
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def create
build_resource(sign_up_params)
if params[:token].present?
@token = params[:token]
- Read upRead up
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 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
- Read upRead up
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 = []
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
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?
Method initialize_from_parsed_data
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.initialize_from_parsed_data(result)
release_date = Date.parse(result[:release_date]) if result[:release_date].present?
vote_average = result[:vote_average].present? ? result[:vote_average].round(1) : 0
runtime = result[:runtime].presence || 0
Method create
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def create
@invite = Invite.new(invite_params)
@invite.email = @invite.email.strip if @invite.email.present?
@invite[:token] = @invite.generate_token
@invitee = @invite.find_invitee
- Read upRead up
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 create
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
@invite = Invite.new(invite_params)
@invite.email = @invite.email.strip if @invite.email.present?
@invite[:token] = @invite.generate_token
@invitee = @invite.find_invitee
Method movies_index_sort_handler
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def movies_index_sort_handler(sort_by)
@sort_by = sort_by
case @sort_by
when "title"
Method update
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
resource_updated = update_resource(resource, account_update_params)
- Read upRead up
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 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 = []
- Read upRead up
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(
Method create
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
build_resource(sign_up_params)
if params[:token].present?
@token = params[:token]
Method parse_movie_params_for_display
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.parse_movie_params_for_display(params)
output = {}
output[:actor_name_display] = "#{params[:actor_name].titlecase} movies" if params[:actor_name].present?
output[:mpaa_rating_display] = "Rated #{params[:mpaa_rating]}" if params[:mpaa_rating].present?