nesquena/rabl

View on GitHub

Showing 32 of 32 total issues

Class Engine has 41 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Engine
    include Helpers
    include Partials
    include Helpers::Escaper

Severity: Minor
Found in lib/rabl/engine.rb - About 5 hrs to fix

    Method data_name has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        def data_name(data_token)
          return unless data_token # nil or false
    
          return data_token.values.first if data_token.is_a?(Hash) # @user => :user
    
    
    Severity: Minor
    Found in lib/rabl/helpers.rb - About 4 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

    File engine.rb has 282 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Rabl
      class Engine
        include Helpers
        include Partials
        include Helpers::Escaper
    Severity: Minor
    Found in lib/rabl/engine.rb - About 2 hrs to fix

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

            def fetch_rails_source(file, options = {})
              # use Rails template resolution mechanism if possible (find_template)
              source_format = request_format if defined?(request_format)
      
              if source_format && context_scope.respond_to?(:lookup_context) # Rails 3
      Severity: Minor
      Found in lib/rabl/sources.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

      Function exports has 68 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      module.exports = function(api) {
        var validEnv = ['development', 'test', 'production']
        var currentEnv = api.env()
        var isDevelopmentEnv = api.env('development')
        var isProductionEnv = api.env('production')
      Severity: Major
      Found in fixtures/rails6/babel.config.js - About 2 hrs to fix

        Class Builder has 22 methods (exceeds 20 allowed). Consider refactoring.
        Open

          class Builder
            include Helpers
            include Partials
        
            SETTING_TYPES = {
        Severity: Minor
        Found in lib/rabl/builder.rb - About 2 hrs to fix

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

            create_table "phone_numbers", force: :cascade do |t|
              t.integer "user_id"
              t.boolean "is_primary"
              t.string  "area_code"
              t.string  "prefix"
          Severity: Major
          Found in fixtures/rails5_api/db/schema.rb and 2 other locations - About 1 hr to fix
          fixtures/rails4/db/schema.rb on lines 16..39
          fixtures/rails5/db/schema.rb on lines 15..38

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

          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

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

            create_table "phone_numbers", :force => true do |t|
              t.integer "user_id"
              t.boolean "is_primary"
              t.string  "area_code"
              t.string  "prefix"
          Severity: Major
          Found in fixtures/padrino_test/db/schema.rb and 2 other locations - About 1 hr to fix
          fixtures/rails2/db/schema.rb on lines 14..37
          fixtures/rails3/db/schema.rb on lines 16..39

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

          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

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

            create_table "phone_numbers", :force => true do |t|
              t.integer "user_id"
              t.boolean "is_primary"
              t.string  "area_code"
              t.string  "prefix"
          Severity: Major
          Found in fixtures/rails3/db/schema.rb and 2 other locations - About 1 hr to fix
          fixtures/padrino_test/db/schema.rb on lines 16..39
          fixtures/rails2/db/schema.rb on lines 14..37

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

          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

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

            create_table "phone_numbers", force: :cascade do |t|
              t.integer "user_id"
              t.boolean "is_primary"
              t.string  "area_code"
              t.string  "prefix"
          Severity: Major
          Found in fixtures/rails5/db/schema.rb and 2 other locations - About 1 hr to fix
          fixtures/rails4/db/schema.rb on lines 16..39
          fixtures/rails5_api/db/schema.rb on lines 15..38

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

          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

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

            create_table "phone_numbers", force: :cascade do |t|
              t.integer "user_id"
              t.boolean "is_primary"
              t.string  "area_code"
              t.string  "prefix"
          Severity: Major
          Found in fixtures/rails4/db/schema.rb and 2 other locations - About 1 hr to fix
          fixtures/rails5/db/schema.rb on lines 15..38
          fixtures/rails5_api/db/schema.rb on lines 15..38

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

          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

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

            create_table "phone_numbers", :force => true do |t|
              t.integer "user_id"
              t.boolean "is_primary"
              t.string  "area_code"
              t.string  "prefix"
          Severity: Major
          Found in fixtures/rails2/db/schema.rb and 2 other locations - About 1 hr to fix
          fixtures/padrino_test/db/schema.rb on lines 16..39
          fixtures/rails3/db/schema.rb on lines 16..39

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

          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

          Method fetch_source has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def fetch_source(file, options = {})
                view_paths = Array(options[:view_path]) + Array(Rabl.configuration.view_paths)
          
                Rabl.source_cache(file, view_paths) do
                  file_path = \
          Severity: Minor
          Found in lib/rabl/sources.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 to_hash has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              def to_hash(object = nil, settings = nil, options = nil)
                @_object = object           if object
                @options.merge!(options)    if options
                @settings.merge!(settings)  if settings
          
          
          Severity: Minor
          Found in lib/rabl/builder.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 initialize has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def initialize
                @include_json_root                            = true
                @include_child_root                           = true
                @include_msgpack_root                         = true
                @include_plist_root                           = true
          Severity: Minor
          Found in lib/rabl/configuration.rb - About 1 hr to fix

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

              config.cache_classes = true
            
              # Do not eager load code on boot. This avoids loading your whole application
              # just for the purpose of running a single test. If you are using a tool that
              # preloads Rails for running tests, you may have to set it to true.
            Severity: Minor
            Found in fixtures/rails5/config/environments/test.rb and 1 other location - About 55 mins to fix
            fixtures/rails5_api/config/environments/test.rb on lines 8..38

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

            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

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

              config.cache_classes = true
            
              # Do not eager load code on boot. This avoids loading your whole application
              # just for the purpose of running a single test. If you are using a tool that
              # preloads Rails for running tests, you may have to set it to true.
            Severity: Minor
            Found in fixtures/rails5_api/config/environments/test.rb and 1 other location - About 55 mins to fix
            fixtures/rails5/config/environments/test.rb on lines 8..38

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

            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

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

                def object(template_data)
                  current_data  = (@_locals[:object].nil? || template_data == false) ? template_data : @_locals[:object]
                  @_data_object = data_object(current_data)
                  @_root_name_data = template_data.is_a?(Hash) && !current_data.is_a?(Hash) ? template_data : current_data
                  @_root_name_data = @_root_name_data.values.first if @_root_name_data.is_a?(Hash)
            Severity: Minor
            Found in lib/rabl/engine.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 merge_engines_into_result has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                  def merge_engines_into_result
                    engines.each do |engine|
                      case engine
                      when Hash
                        # engine was stored in the form { name => #<Engine> }
            Severity: Minor
            Found in lib/rabl/builder.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 root_name has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def root_name
                  return @_data_name if defined?(@_data_name)
            
                  @_data_name = @_options[:object_root_name] || begin
                    data = defined?(@_root_name_data) ? @_root_name_data : (@_locals[:object].nil? ? root_object : @_locals[:object])
            Severity: Minor
            Found in lib/rabl/engine.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

            Severity
            Category
            Status
            Source
            Language