gitshowcase/gitshowcase

View on GitHub
app/services/user/skills_service.rb

Summary

Maintainability
A
1 hr
Test Coverage

Cyclomatic complexity for set is too high. [7/6]
Open

  def set(skills)
    keys = skills.keys
    skills = convert_from_arrays(skills) if keys.size == 2 && keys.include?(:name) && keys.include?(:mastery)

    parsed = {}
Severity: Minor
Found in app/services/user/skills_service.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 has too many lines. [11/10]
Open

  def set(skills)
    keys = skills.keys
    skills = convert_from_arrays(skills) if keys.size == 2 && keys.include?(:name) && keys.include?(:mastery)

    parsed = {}
Severity: Minor
Found in app/services/user/skills_service.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.

Method set has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def set(skills)
    keys = skills.keys
    skills = convert_from_arrays(skills) if keys.size == 2 && keys.include?(:name) && keys.include?(:mastery)

    parsed = {}
Severity: Minor
Found in app/services/user/skills_service.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

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

class User::SkillsService < ApplicationService
Severity: Minor
Found in app/services/user/skills_service.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.

Line is too long. [109/80]
Open

    skills = convert_from_arrays(skills) if keys.size == 2 && keys.include?(:name) && keys.include?(:mastery)
Severity: Minor
Found in app/services/user/skills_service.rb by rubocop

Prefer each over for.
Open

    for i in 0..params[:name].size
Severity: Minor
Found in app/services/user/skills_service.rb by rubocop

This cop looks for uses of the for keyword, or each method. The preferred alternative is set in the EnforcedStyle configuration parameter. An each call with a block on a single line is always allowed, however.

Missing top-level class documentation comment.
Open

class User::SkillsService < ApplicationService
Severity: Minor
Found in app/services/user/skills_service.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

There are no issues that match your filters.

Category
Status