hummingbird-me/hummingbird

View on GitHub
app/api/api_v1.rb

Summary

Maintainability
D
1 day
Test Coverage

File api_v1.rb has 479 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class API_v1 < Grape::API
  version 'v1', using: :path, format: :json, vendor: 'hummingbird'
  formatter :json, lambda {|object, env| MultiJson.dump(object) }
  rescue_from ActiveRecord::RecordNotFound

Severity: Minor
Found in app/api/api_v1.rb - About 7 hrs to fix

    Method present_story has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def present_story(story, current_user, title_language_preference)
          json = {
            id: story.id,
            story_type: story.story_type,
            user: present_miniuser(story.user),
    Severity: Minor
    Found in app/api/api_v1.rb - 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

    Method present_story has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def present_story(story, current_user, title_language_preference)
          json = {
            id: story.id,
            story_type: story.story_type,
            user: present_miniuser(story.user),
    Severity: Minor
    Found in app/api/api_v1.rb - About 1 hr to fix

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

          def current_user
            return env['current_user'] if env.has_key?('current_user')
      
            if params[:auth_token] || cookies[:auth_token]
              token = Token.new(params[:auth_token] || cookies[:auth_token])
      Severity: Minor
      Found in app/api/api_v1.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 present_anime has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def present_anime(anime, title_language_preference)
            if anime
              {
                id: anime.id,
                mal_id: anime.mal_id,
      Severity: Minor
      Found in app/api/api_v1.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

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

          def find_user(id)
            begin
              if id == "me" and user_signed_in?
                current_user
              else
      Severity: Minor
      Found in app/api/api_v1.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

      There are no issues that match your filters.

      Category
      Status