marcelobarreto/postgrest-rb

View on GitHub

Showing 17 of 17 total issues

Assignment Branch Condition size for call is too high. [16.16/15]
Open

    def call
      raise InvalidHTTPMethod unless valid_http_method?

      @response = Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl?) do |http|
        @request = create_request
Severity: Minor
Found in lib/postgrest/http.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

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

      def upsert(values, extra_headers: {})
        extra_headers[:Prefer] ||= 'return=representation,resolution=merge-duplicates'
        request = HTTP.new(uri: uri, body: values, http_method: :post, headers: headers.merge(extra_headers))

        BaseBuilder.new(request)
Severity: Minor
Found in lib/postgrest/builders/query_builder.rb and 1 other location - About 15 mins to fix
lib/postgrest/builders/query_builder.rb on lines 33..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 26.

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 update(values, extra_headers: {})
        extra_headers[:Prefer] ||= 'return=representation'
        request = HTTP.new(uri: uri, body: values, http_method: :patch, headers: headers.merge(extra_headers))

        FilterBuilder.new(request)
Severity: Minor
Found in lib/postgrest/builders/query_builder.rb and 1 other location - About 15 mins to fix
lib/postgrest/builders/query_builder.rb on lines 26..30

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

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

Line is too long. [109/80]
Open

        request = HTTP.new(uri: uri, body: values, http_method: :post, headers: headers.merge(extra_headers))

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Line is too long. [85/80]
Open

    `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
Severity: Minor
Found in postgrest.gemspec by rubocop

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Line is too long. [86/80]
Open

        extra_headers[:Prefer] ||= 'return=representation,resolution=merge-duplicates'

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Line is too long. [90/80]
Open

      Builders::QueryBuilder.new(url: "#{url}/#{table}", headers: headers, schema: schema)
Severity: Minor
Found in lib/postgrest/client.rb by rubocop

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Line is too long. [110/80]
Open

        request = HTTP.new(uri: uri, body: values, http_method: :patch, headers: headers.merge(extra_headers))

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Use #key? instead of #keys.include?.
Open

      METHODS.keys.include?(http_method)
Severity: Minor
Found in lib/postgrest/http.rb by rubocop

This cop checks for inefficient searching of keys and values within hashes.

Hash#keys.include? is less efficient than Hash#key? because the former allocates a new array and then performs an O(n) search through that array, while Hash#key? does not allocate any array and performs a faster O(1) search for the key.

Hash#values.include? is less efficient than Hash#value?. While they both perform an O(n) search through all of the values, calling values allocates a new array while using value? does not.

Example:

# bad
{ a: 1, b: 2 }.keys.include?(:a)
{ a: 1, b: 2 }.keys.include?(:z)
h = { a: 1, b: 2 }; h.keys.include?(100)

# good
{ a: 1, b: 2 }.key?(:a)
{ a: 1, b: 2 }.has_key?(:z)
h = { a: 1, b: 2 }; h.key?(100)

# bad
{ a: 1, b: 2 }.values.include?(2)
{ a: 1, b: 2 }.values.include?('garbage')
h = { a: 1, b: 2 }; h.values.include?(nil)

# good
{ a: 1, b: 2 }.value?(2)
{ a: 1, b: 2 }.has_value?('garbage')
h = { a: 1, b: 2 }; h.value?(nil)

Freeze mutable objects assigned to constants.
Open

    DEFAULT_SCHEMA = 'public'
Severity: Minor
Found in lib/postgrest/client.rb by rubocop

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Example:

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

# good
CONST = <<~TESTING.freeze
This is a heredoc
TESTING

Line is too long. [108/80]
Open

        request = HTTP.new(uri: uri, query: {}, http_method: :delete, headers: headers.merge(extra_headers))

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

rescue at 20, 10 is not aligned with begin at 18, 18.
Open

          rescue StandardError

This cop checks whether the rescue and ensure keywords are aligned properly.

Example:

# bad
begin
  something
  rescue
  puts 'error'
end

# good
begin
  something
rescue
  puts 'error'
end

Freeze mutable objects assigned to constants.
Open

    USER_AGENT = 'PostgREST Ruby Client'
Severity: Minor
Found in lib/postgrest/http.rb by rubocop

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Example:

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

# good
CONST = <<~TESTING.freeze
This is a heredoc
TESTING

Line is too long. [82/80]
Open

      @response = Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl?) do |http|
Severity: Minor
Found in lib/postgrest/http.rb by rubocop

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Freeze mutable objects assigned to constants.
Open

  VERSION = '0.2.0'
Severity: Minor
Found in lib/postgrest/version.rb by rubocop

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Example:

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

# good
CONST = <<~TESTING.freeze
This is a heredoc
TESTING

Line is too long. [113/80]
Open

        request = HTTP.new(uri: uri, query: { select: columns.join(',') }, headers: headers.merge(extra_headers))

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Line is too long. [87/80]
Open

  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Severity: Minor
Found in postgrest.gemspec by rubocop

This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

Severity
Category
Status
Source
Language