marceloboeira/feedcast

View on GitHub
app/api/api/v1/category.rb

Summary

Maintainability
A
15 mins
Test Coverage
A
100%

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

      get do
        slug = params[:slug]

        cache(key: "api:categories:#{slug}", expires_in: 1.hour) do
          category = ::Category.find(slug)
Severity: Minor
Found in app/api/api/v1/category.rb and 1 other location - About 15 mins to fix
app/api/api/v1/channel.rb on lines 17..23

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

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

Missing magic comment # frozen_string_literal: true.
Open

class API::V1::Category < Grape::API
Severity: Minor
Found in app/api/api/v1/category.rb by rubocop

This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Example: EnforcedStyle: when_needed (default)

# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
  # ...
end

# good
# frozen_string_literal: true

module Foo
  # ...
end

Example: EnforcedStyle: always

# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Example: EnforcedStyle: never

# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true

module Baz
  # ...
end

# good
module Baz
  # ...
end

Do not use parallel assignment.
Open

      page, per_page = params[:page], params[:per_page]
Severity: Minor
Found in app/api/api/v1/category.rb by rubocop

Checks for simple usages of parallel assignment. This will only complain when the number of variables being assigned matched the number of assigning variables.

Example:

# bad
a, b, c = 1, 2, 3
a, b, c = [1, 2, 3]

# good
one, two = *foo
a, b = foo()
a, b = b, a

a = 1
b = 2
c = 3

Missing top-level class documentation comment.
Open

class API::V1::Category < Grape::API
Severity: Minor
Found in app/api/api/v1/category.rb by rubocop

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Line is too long. [82/80]
Open

      cache(key: "api:categories:list:#{page}:#{per_page}", expires_in: 1.hour) do
Severity: Minor
Found in app/api/api/v1/category.rb by rubocop

Use nested module/class definitions instead of compact style.
Open

class API::V1::Category < Grape::API
Severity: Minor
Found in app/api/api/v1/category.rb by rubocop

This cop checks the style of children definitions at classes and modules. Basically there are two different styles:

Example: EnforcedStyle: nested (default)

# good
# have each child on its own line
class Foo
  class Bar
  end
end

Example: EnforcedStyle: compact

# good
# combine definitions as much as possible
class Foo::Bar
end

The compact style is only forced for classes/modules with one child.

There are no issues that match your filters.

Category
Status