locaweb/cassette

View on GitHub

Showing 65 of 65 total issues

Assignment Branch Condition size for ticket_user is too high. [25.26/15]
Open

    def ticket_user(ticket, service = config.service)
      cache.fetch_authentication(ticket, service) do
        begin
          logger.info("Validating #{ticket} on #{validate_path}")

Severity: Minor
Found in lib/cassette/authentication.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [20/10]
Open

    def ticket_user(ticket, service = config.service)
      cache.fetch_authentication(ticket, service) do
        begin
          logger.info("Validating #{ticket} on #{validate_path}")

Severity: Minor
Found in lib/cassette/authentication.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for fetch is too high. [21.42/15]
Open

    def fetch(key, options = {}, &block)
      if options[:max_uses].to_i != 0
        uses_key = self.uses_key(key)
        uses = backend.read(uses_key, raw: true)
        backend.write(uses_key, 0, raw: true, expires_in: options[:expires_in]) if uses.nil?
Severity: Minor
Found in lib/cassette/cache.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [16/10]
Open

      def initialize(response)
        namespaces = { "cas" => "http://www.yale.edu/tp/cas" }
        query = "//cas:serviceResponse/cas:authenticationSuccess/cas:user"

        document = REXML::Document.new(response)

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [12/10]
Open

    def fetch(key, options = {}, &block)
      if options[:max_uses].to_i != 0
        uses_key = self.uses_key(key)
        uses = backend.read(uses_key, raw: true)
        backend.write(uses_key, 0, raw: true, expires_in: options[:expires_in]) if uses.nil?
Severity: Minor
Found in lib/cassette/cache.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

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

    def initialize(opts = {})
      self.config = opts.fetch(:config, Cassette.config)
      self.logger = opts.fetch(:logger, Cassette.logger)
      self.http   = opts.fetch(:http_client, Cassette::Http::Request.new(config))
      self.cache  = opts.fetch(:cache, Cassette::Client::Cache.new(logger))
Severity: Minor
Found in lib/cassette/client.rb and 1 other location - About 40 mins to fix
lib/cassette/authentication.rb on lines 10..14

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

    def initialize(opts = {})
      self.config = opts.fetch(:config, Cassette.config)
      self.logger = opts.fetch(:logger, Cassette.logger)
      self.http   = opts.fetch(:http_client, Cassette::Http::Request.new(config))
      self.cache  = opts.fetch(:cache, Cassette::Authentication::Cache.new(logger))
Severity: Minor
Found in lib/cassette/authentication.rb and 1 other location - About 40 mins to fix
lib/cassette/client.rb on lines 8..12

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

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

    def fetch(key, options = {}, &block)
      if options[:max_uses].to_i != 0
        uses_key = self.uses_key(key)
        uses = backend.read(uses_key, raw: true)
        backend.write(uses_key, 0, raw: true, expires_in: options[:expires_in]) if uses.nil?
Severity: Minor
Found in lib/cassette/cache.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

Use module_function instead of extend self.
Open

  extend self
Severity: Minor
Found in lib/cassette.rb by rubocop

This cops checks for use of extend self or module_function in a module.

Supported styles are: modulefunction, extendself.

Example: EnforcedStyle: module_function (default)

# bad
module Test
  extend self
  # ...
end

# good
module Test
  module_function
  # ...
end

Example: EnforcedStyle: extend_self

# bad
module Test
  module_function
  # ...
end

# good
module Test
  extend self
  # ...
end

These offenses are not auto-corrected since there are different implications to each approach.

Place the . on the next line, together with the method name.
Open

            elements.

This cop checks the . position in multi-line method calls.

Example: EnforcedStyle: leading (default)

# bad
something.
  mehod

# good
something
  .method

Example: EnforcedStyle: trailing

# bad
something
  .method

# good
something.
  mehod

Align map with Hash[REXML::XPath. on line 20.
Open

            map { |e| [e.name, e.text] }]

This cop checks the indentation of the method name part in method calls that span more than one line.

Example: EnforcedStyle: aligned

# bad
while myvariable
.b
  # do something
end

# good
while myvariable
      .b
  # do something
end

# good
Thing.a
     .b
     .c

Example: EnforcedStyle: indented

# good
while myvariable
  .b

  # do something
end

Example: EnforcedStyle: indentedrelativeto_receiver

# good
while myvariable
        .a
        .b

  # do something
end

# good
myvariable = Thing
               .a
               .b
               .c

unexpected token error (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
Open

                                   config&.base_authority)
Severity: Minor
Found in lib/cassette/authentication/user.rb by rubocop

Unnecessary utf-8 encoding comment.
Open

# encoding: UTF-8
Severity: Minor
Found in lib/cassette/rubycas.rb by rubocop

Unnecessary utf-8 encoding comment.
Open

# encoding: UTF-8
Severity: Minor
Found in lib/cassette/client/cache.rb by rubocop

Always use raise to signal exceptions.
Open

        fail Cassette::Errors::Forbidden unless current_user.has_role?(role)
Severity: Minor
Found in lib/cassette/rubycas/helper.rb by rubocop

This cop checks for uses of fail and raise.

Example: EnforcedStyle: only_raise (default)

# The `only_raise` style enforces the sole use of `raise`.
# bad
begin
  fail
rescue Exception
  # handle it
end

def watch_out
  fail
rescue Exception
  # handle it
end

Kernel.fail

# good
begin
  raise
rescue Exception
  # handle it
end

def watch_out
  raise
rescue Exception
  # handle it
end

Kernel.raise

Example: EnforcedStyle: only_fail

# The `only_fail` style enforces the sole use of `fail`.
# bad
begin
  raise
rescue Exception
  # handle it
end

def watch_out
  raise
rescue Exception
  # handle it
end

Kernel.raise

# good
begin
  fail
rescue Exception
  # handle it
end

def watch_out
  fail
rescue Exception
  # handle it
end

Kernel.fail

Example: EnforcedStyle: semantic

# The `semantic` style enforces the use of `fail` to signal an
# exception, then will use `raise` to trigger an offense after
# it has been rescued.
# bad
begin
  raise
rescue Exception
  # handle it
end

def watch_out
  # Error thrown
rescue Exception
  fail
end

Kernel.fail
Kernel.raise

# good
begin
  fail
rescue Exception
  # handle it
end

def watch_out
  fail
rescue Exception
  raise 'Preferably with descriptive message'
end

explicit_receiver.fail
explicit_receiver.raise

Unnecessary utf-8 encoding comment.
Open

# encoding: UTF-8

Unnecessary utf-8 encoding comment.
Open

# encoding: UTF-8

Always use raise to signal exceptions.
Open

      fail Cassette::Errors::AuthorizationRequired if ticket.blank?
Severity: Minor
Found in lib/cassette/authentication.rb by rubocop

This cop checks for uses of fail and raise.

Example: EnforcedStyle: only_raise (default)

# The `only_raise` style enforces the sole use of `raise`.
# bad
begin
  fail
rescue Exception
  # handle it
end

def watch_out
  fail
rescue Exception
  # handle it
end

Kernel.fail

# good
begin
  raise
rescue Exception
  # handle it
end

def watch_out
  raise
rescue Exception
  # handle it
end

Kernel.raise

Example: EnforcedStyle: only_fail

# The `only_fail` style enforces the sole use of `fail`.
# bad
begin
  raise
rescue Exception
  # handle it
end

def watch_out
  raise
rescue Exception
  # handle it
end

Kernel.raise

# good
begin
  fail
rescue Exception
  # handle it
end

def watch_out
  fail
rescue Exception
  # handle it
end

Kernel.fail

Example: EnforcedStyle: semantic

# The `semantic` style enforces the use of `fail` to signal an
# exception, then will use `raise` to trigger an offense after
# it has been rescued.
# bad
begin
  raise
rescue Exception
  # handle it
end

def watch_out
  # Error thrown
rescue Exception
  fail
end

Kernel.fail
Kernel.raise

# good
begin
  fail
rescue Exception
  # handle it
end

def watch_out
  fail
rescue Exception
  raise 'Preferably with descriptive message'
end

explicit_receiver.fail
explicit_receiver.raise

URI.unescape method is obsolete and should not be used. Instead, use CGI.unescape, URI.decode_www_form or URI.decode_www_form_component depending on your specific use case.
Open

        [params['logoutRequest'], URI.unescape(params['logoutRequest'])].find { |xml| xml =~ LOGOUT_PAYLOAD_EXPR }

This cop identifies places where URI.escape can be replaced by CGI.escape, URI.encode_www_form or URI.encode_www_form_component depending on your specific use case. Also this cop identifies places where URI.unescape can be replaced by CGI.unescape, URI.decode_www_form or URI.decode_www_form_component depending on your specific use case.

Example:

# bad
URI.escape('http://example.com')
URI.encode('http://example.com')

# good
CGI.escape('http://example.com')
URI.encode_www_form([['example', 'param'], ['lang', 'en']])
URI.encode_www_form(page: 10, locale: 'en')
URI.encode_www_form_component('http://example.com')

# bad
URI.unescape(enc_uri)
URI.decode(enc_uri)

# good
CGI.unescape(enc_uri)
URI.decode_www_form(enc_uri)
URI.decode_www_form_component(enc_uri)

When using method_missing, define respond_to_missing? and fall back on super.
Open

    def self.method_missing(name, *args)
      @default_authentication ||= new
      @default_authentication.send(name, *args)
    end
Severity: Minor
Found in lib/cassette/authentication.rb by rubocop

This cop checks for the presence of method_missing without also defining respond_to_missing? and falling back on super.

Example:

#bad
def method_missing(name, *args)
  # ...
end

#good
def respond_to_missing?(name, include_private)
  # ...
end

def method_missing(name, *args)
  # ...
  super
end
Severity
Category
Status
Source
Language