CartoDB/cartodb20

View on GitHub
app/controllers/carto/api/user_presenter.rb

Summary

Maintainability
D
2 days
Test Coverage

Method data has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

      def data(options = {})
        return {} if @user.nil?
        db_size_in_bytes = @user.db_size_in_bytes

        data = {
Severity: Minor
Found in app/controllers/carto/api/user_presenter.rb - About 6 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 data has 164 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def data(options = {})
        return {} if @user.nil?
        db_size_in_bytes = @user.db_size_in_bytes

        data = {
Severity: Major
Found in app/controllers/carto/api/user_presenter.rb - About 6 hrs to fix

    File user_presenter.rb has 277 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require_relative 'group_presenter'
    
    module Carto
      module Api
        class UserPresenter
    Severity: Minor
    Found in app/controllers/carto/api/user_presenter.rb - About 2 hrs to fix

      Method to_poro has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def to_poro
              return {} if @user.nil?
              return to_public_poro unless current_viewer && @user.viewable_by?(current_viewer)
      
              poro = {
      Severity: Minor
      Found in app/controllers/carto/api/user_presenter.rb - About 1 hr to fix

        Method to_poro has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

              def to_poro
                return {} if @user.nil?
                return to_public_poro unless current_viewer && @user.viewable_by?(current_viewer)
        
                poro = {
        Severity: Minor
        Found in app/controllers/carto/api/user_presenter.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

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

                  here_isolines: {
                    quota:       @user.organization_user? ? @user.organization.here_isolines_quota : @user.here_isolines_quota,
                    block_price: @user.organization_user? ? @user.organization.here_isolines_block_price : @user.here_isolines_block_price,
                    monthly_use: @user.organization_user? ? @user.organization.get_here_isolines_calls : @user.get_here_isolines_calls,
                    hard_limit:  @user.hard_here_isolines_limit?
        Severity: Minor
        Found in app/controllers/carto/api/user_presenter.rb and 2 other locations - About 25 mins to fix
        app/controllers/carto/api/user_presenter.rb on lines 168..173
        app/controllers/carto/api/user_presenter.rb on lines 180..185

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

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

                  mapzen_routing: {
                    quota:       @user.organization_user? ? @user.organization.mapzen_routing_quota : @user.mapzen_routing_quota,
                    block_price: @user.organization_user? ? @user.organization.mapzen_routing_block_price : @user.mapzen_routing_block_price,
                    monthly_use: @user.organization_user? ? @user.organization.get_mapzen_routing_calls : @user.get_mapzen_routing_calls,
                    hard_limit:  @user.hard_mapzen_routing_limit?
        Severity: Minor
        Found in app/controllers/carto/api/user_presenter.rb and 2 other locations - About 25 mins to fix
        app/controllers/carto/api/user_presenter.rb on lines 168..173
        app/controllers/carto/api/user_presenter.rb on lines 174..179

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

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

                  geocoding: {
                    quota:       @user.organization_user? ? @user.organization.geocoding_quota : @user.geocoding_quota,
                    block_price: @user.organization_user? ? @user.organization.geocoding_block_price : @user.geocoding_block_price,
                    monthly_use: @user.organization_user? ? @user.organization.get_geocoding_calls : @user.get_geocoding_calls,
                    hard_limit:  @user.hard_geocoding_limit?
        Severity: Minor
        Found in app/controllers/carto/api/user_presenter.rb and 2 other locations - About 25 mins to fix
        app/controllers/carto/api/user_presenter.rb on lines 174..179
        app/controllers/carto/api/user_presenter.rb on lines 180..185

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

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

                  actions: {
                    private_tables: @user.private_tables_enabled,
                    private_maps: @user.private_maps_enabled?,
                    remove_logo: @user.remove_logo?,
                    sync_tables: @user.sync_tables_enabled,
        Severity: Minor
        Found in app/controllers/carto/api/user_presenter.rb and 2 other locations - About 20 mins to fix
        app/controllers/carto/api/mobile_app_presenter.rb on lines 14..24
        app/controllers/carto/api/user_creation_presenter.rb on lines 10..20

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

        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