gregbeech/xenon

View on GitHub

Showing 51 of 51 total issues

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

module Xenon
  class Headers
    # http://tools.ietf.org/html/rfc7232#section-3.2
    class IfNoneMatch < ListHeader 'If-None-Match'
      def initialize(*etags)
Severity: Major
Found in xenon-http/lib/xenon/headers/if_none_match.rb and 1 other location - About 3 hrs to fix
xenon-http/lib/xenon/headers/if_match.rb on lines 6..50

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

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

module Xenon
  class Headers
    # http://tools.ietf.org/html/rfc7232#section-3.1
    class IfMatch < ListHeader 'If-Match'
      def initialize(*etags)
Severity: Major
Found in xenon-http/lib/xenon/headers/if_match.rb and 1 other location - About 3 hrs to fix
xenon-http/lib/xenon/headers/if_none_match.rb on lines 6..50

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

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

Cyclomatic complexity for convert_param_type is too high. [9/6]
Open

      def convert_param_type(value, type)
        if type == String then value
        elsif type == Symbol then value.to_sym
        elsif type == Bignum || type == Fixnum || type == Integer then Integer(value)
        elsif type == Float then Float(value)

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Cyclomatic complexity for default_rejection_handler is too high. [9/6]
Open

    def default_rejection_handler(rejections)
      puts "handle_rejections: #{rejections}"
      if rejections.empty?
        fail_with 404
      else
Severity: Minor
Found in xenon-routing/lib/xenon/api.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method default_rejection_handler has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def default_rejection_handler(rejections)
      puts "handle_rejections: #{rejections}"
      if rejections.empty?
        fail_with 404
      else
Severity: Minor
Found in xenon-routing/lib/xenon/api.rb - About 1 hr to fix

    Method convert_param_type has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def convert_param_type(value, type)
            if type == String then value
            elsif type == Symbol then value.to_sym
            elsif type == Bignum || type == Fixnum || type == Integer then Integer(value)
            elsif type == Float then Float(value)
    Severity: Minor
    Found in xenon-routing/lib/xenon/routing/param_directives.rb - About 55 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

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

        class AcceptCharsetHeaderTransform < HeaderTransform
          rule(charset: simple(:c), q: simple(:q)) { CharsetRange.new(c, q) }
          rule(charset: simple(:c)) { CharsetRange.new(c) }
          rule(accept_charset: sequence(:cr)) { Headers::AcceptCharset.new(*cr) }
          rule(accept_charset: simple(:cr)) { Headers::AcceptCharset.new(cr) }
    Severity: Minor
    Found in xenon-http/lib/xenon/headers/accept_charset.rb and 1 other location - About 55 mins to fix
    xenon-http/lib/xenon/headers/accept_language.rb on lines 52..56

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

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

        class AcceptLanguageHeaderTransform < HeaderTransform
          rule(language: simple(:e), q: simple(:q)) { LanguageRange.new(e, q) }
          rule(language: simple(:e)) { LanguageRange.new(e) }
          rule(accept_language: sequence(:lr)) { Headers::AcceptLanguage.new(*lr) }
          rule(accept_language: simple(:lr)) { Headers::AcceptLanguage.new(lr) }
    Severity: Minor
    Found in xenon-http/lib/xenon/headers/accept_language.rb and 1 other location - About 55 mins to fix
    xenon-http/lib/xenon/headers/accept_charset.rb on lines 52..56

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

    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 call! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def call!(env)
          @context = Routing::Context.new(Request.new(Rack::Request.new(env)), Response.new)
    
          accept = @context.request.header('Accept')
          response_marshaller = accept ? self.class.response_marshaller(accept.media_ranges) : self.class.marshallers.first
    Severity: Minor
    Found in xenon-routing/lib/xenon/api.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 params has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def params(*param_defs)
            param_hash do |hash|
              values = Array(param_defs).map do |param_def|
                if param_def.respond_to?(:has_key?)
                  name, settings = param_def.each_pair.first
    Severity: Minor
    Found in xenon-routing/lib/xenon/routing/param_directives.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 default_rejection_handler has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def default_rejection_handler(rejections)
          puts "handle_rejections: #{rejections}"
          if rejections.empty?
            fail_with 404
          else
    Severity: Minor
    Found in xenon-routing/lib/xenon/api.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

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

      class CharsetRange
        attr_reader :charset, :q
    
        DEFAULT_Q = 1.0
    
    
    Severity: Major
    Found in xenon-http/lib/xenon/headers/accept_charset.rb and 2 other locations - About 40 mins to fix
    xenon-http/lib/xenon/headers/accept_encoding.rb on lines 5..22
    xenon-http/lib/xenon/headers/accept_language.rb on lines 5..22

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

    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

      class LanguageRange
        attr_reader :language, :q
    
        DEFAULT_Q = 1.0
    
    
    Severity: Major
    Found in xenon-http/lib/xenon/headers/accept_language.rb and 2 other locations - About 40 mins to fix
    xenon-http/lib/xenon/headers/accept_charset.rb on lines 5..22
    xenon-http/lib/xenon/headers/accept_encoding.rb on lines 5..22

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

    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

      class ContentCodingRange
        attr_reader :coding, :q
    
        DEFAULT_Q = 1.0
    
    
    Severity: Major
    Found in xenon-http/lib/xenon/headers/accept_encoding.rb and 2 other locations - About 40 mins to fix
    xenon-http/lib/xenon/headers/accept_charset.rb on lines 5..22
    xenon-http/lib/xenon/headers/accept_language.rb on lines 5..22

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

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

      class Headers
        # http://tools.ietf.org/html/rfc7231#section-5.3.3
        class AcceptCharset < ListHeader 'Accept-Charset'
          def initialize(*charset_ranges)
            super(charset_ranges.sort_by.with_index { |mr, i| [mr, -i] }.reverse)
    Severity: Major
    Found in xenon-http/lib/xenon/headers/accept_charset.rb and 3 other locations - About 35 mins to fix
    xenon-http/lib/xenon/headers/accept.rb on lines 6..17
    xenon-http/lib/xenon/headers/accept_encoding.rb on lines 26..37
    xenon-http/lib/xenon/headers/accept_language.rb on lines 26..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 34.

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

      class Headers
        # http://tools.ietf.org/html/rfc7231#section-5.3.2
        class Accept < ListHeader 'Accept'
          def initialize(*media_ranges)
            super(media_ranges.sort_by.with_index { |mr, i| [mr, -i] }.reverse)
    Severity: Major
    Found in xenon-http/lib/xenon/headers/accept.rb and 3 other locations - About 35 mins to fix
    xenon-http/lib/xenon/headers/accept_charset.rb on lines 26..37
    xenon-http/lib/xenon/headers/accept_encoding.rb on lines 26..37
    xenon-http/lib/xenon/headers/accept_language.rb on lines 26..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 34.

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

      class Headers
        # http://tools.ietf.org/html/rfc7231#section-5.3.4
        class AcceptEncoding < ListHeader 'Accept-Encoding'
          def initialize(*coding_ranges)
            super(coding_ranges.sort_by.with_index { |mr, i| [mr, -i] }.reverse)
    Severity: Major
    Found in xenon-http/lib/xenon/headers/accept_encoding.rb and 3 other locations - About 35 mins to fix
    xenon-http/lib/xenon/headers/accept.rb on lines 6..17
    xenon-http/lib/xenon/headers/accept_charset.rb on lines 26..37
    xenon-http/lib/xenon/headers/accept_language.rb on lines 26..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 34.

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

      class Headers
        # http://tools.ietf.org/html/rfc7231#section-5.3.5
        class AcceptLanguage < ListHeader 'Accept-Language'
          def initialize(*language_ranges)
            super(language_ranges.sort_by.with_index { |mr, i| [mr, -i] }.reverse)
    Severity: Major
    Found in xenon-http/lib/xenon/headers/accept_language.rb and 3 other locations - About 35 mins to fix
    xenon-http/lib/xenon/headers/accept.rb on lines 6..17
    xenon-http/lib/xenon/headers/accept_charset.rb on lines 26..37
    xenon-http/lib/xenon/headers/accept_encoding.rb on lines 26..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 34.

    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 marshallers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def marshallers(*marshallers)
            @marshallers = marshallers unless marshallers.nil? || marshallers.empty?
            (@marshallers.nil? || @marshallers.empty?) ? DEFAULT_MARSHALLERS : @marshallers
          end
    Severity: Minor
    Found in xenon-routing/lib/xenon/api.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

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

        def to_s
          s = ''
          s << @name if @name
          s << '/' << @version if @version
          if @comment
    Severity: Minor
    Found in xenon-http/lib/xenon/headers/user_agent.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

    Severity
    Category
    Status
    Source
    Language