fga-gpp-mds/2017.1-Escola-X

View on GitHub
app/helpers/reader_helper.rb

Summary

Maintainability
A
1 hr
Test Coverage

Assignment Branch Condition size for mountCurrentDate is too high. [20.98/15]
Open

    def mountCurrentDate() 
    
         #hour = (Time.current.hour - ADJUSTING_FUSE_TO_BRAZILIAN).to_s
         #minute = Time.current.min .to_s
         day = Time.current.day.to_s
Severity: Minor
Found in app/helpers/reader_helper.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. [11/10]
Open

    def mountCurrentDate() 
    
         #hour = (Time.current.hour - ADJUSTING_FUSE_TO_BRAZILIAN).to_s
         #minute = Time.current.min .to_s
         day = Time.current.day.to_s
Severity: Minor
Found in app/helpers/reader_helper.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.

ReaderHelper#mountCurrentDate has approx 7 statements
Open

    def mountCurrentDate() 
Severity: Minor
Found in app/helpers/reader_helper.rb by reek

A method with Too Many Statements is any method that has a large number of lines.

Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

So the following method would score +6 in Reek's statement-counting algorithm:

def parse(arg, argv, &error)
  if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
    return nil, block, nil                                         # +1
  end
  opt = (val = parse_arg(val, &error))[1]                          # +2
  val = conv_arg(*val)                                             # +3
  if opt and !arg
    argv.shift                                                     # +4
  else
    val[0] = nil                                                   # +5
  end
  val                                                              # +6
end

(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

ReaderHelper has 6 constants
Open

module ReaderHelper
Severity: Minor
Found in app/helpers/reader_helper.rb by reek

Too Many Constants is a special case of LargeClass.

Example

Given this configuration

TooManyConstants:
  max_constants: 3

and this code:

class TooManyConstants
  CONST_1 = :dummy
  CONST_2 = :dummy
  CONST_3 = :dummy
  CONST_4 = :dummy
end

Reek would emit the following warning:

test.rb -- 1 warnings:
  [1]:TooManyConstants has 4 constants (TooManyConstants)

ReaderHelper has no descriptive comment
Open

module ReaderHelper
Severity: Minor
Found in app/helpers/reader_helper.rb by reek

Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

Example

Given

class Dummy
  # Do things...
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:Dummy has no descriptive comment (IrresponsibleModule)

Fixing this is simple - just an explaining comment:

# The Dummy class is responsible for ...
class Dummy
  # Do things...
end

ReaderHelper#mountCurrentDate calls 'Time.current' 3 times
Open

         day = Time.current.day.to_s
         month = Time.current.month.to_s
         year = Time.current.year.to_s 
Severity: Minor
Found in app/helpers/reader_helper.rb by reek

Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

Reek implements a check for Duplicate Method Call.

Example

Here's a very much simplified and contrived example. The following method will report a warning:

def double_thing()
  @other.thing + @other.thing
end

One quick approach to silence Reek would be to refactor the code thus:

def double_thing()
  thing = @other.thing
  thing + thing
end

A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

class Other
  def double_thing()
    thing + thing
  end
end

The approach you take will depend on balancing other factors in your code.

ReaderHelper#mountCurrentDate doesn't depend on instance state (maybe move it to another class?)
Open

    def mountCurrentDate() 
Severity: Minor
Found in app/helpers/reader_helper.rb by reek

A Utility Function is any instance method that has no dependency on the state of the instance.

ReaderHelper#mountCurrentDate has the name 'mountCurrentDate'
Open

    def mountCurrentDate() 
Severity: Minor
Found in app/helpers/reader_helper.rb by reek

An Uncommunicative Method Name is a method name that doesn't communicate its intent well enough.

Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

ReaderHelper#mountCurrentDate has the variable name 'correctDate'
Open

         correctDate = year + SPACE_TRACE_SPACE + month + SPACE_TRACE_SPACE + day 
Severity: Minor
Found in app/helpers/reader_helper.rb by reek

An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

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

    def mountCurrentDate() 
    
         #hour = (Time.current.hour - ADJUSTING_FUSE_TO_BRAZILIAN).to_s
         #minute = Time.current.min .to_s
         day = Time.current.day.to_s
Severity: Major
Found in app/helpers/reader_helper.rb and 1 other location - About 1 hr to fix
app/controllers/reader_controller.rb on lines 51..68

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

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

Tab detected.
Open

    DATE_SPACE = "/"
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Tab detected.
Open

    end
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

    DATE_SPACE = "/"
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Extra empty line detected at module body beginning.
Open


    TWO_POINTS = ":"
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cops checks if empty lines around the bodies of modules match the configuration.

Example: EnforcedStyle: empty_lines

# good

module Foo

  def bar
    # ...
  end

end

Example: EnforcedStyle: emptylinesexcept_namespace

# good

module Foo
  module Bar

    # ...

  end
end

Example: EnforcedStyle: emptylinesspecial

# good
module Foo

  def bar; end

end

Example: EnforcedStyle: noemptylines (default)

# good

module Foo
  def bar
    # ...
  end
end

Tab detected.
Open

         year = Time.current.year.to_s 
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Tab detected.
Open

             day = ZERO + day
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Tab detected.
Open

        return correctDate.to_s
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
Open

         if (month.length == SINGLE_CHAR)
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

Example:

# bad
if condition
  do_stuff(bar)
end

unless qux.empty?
  Foo.do_something
end

# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?

Inconsistent indentation detected.
Open

        return correctDate.to_s
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cops checks for inconsistent indentation.

Example:

class A
  def test
    puts 'hello'
     puts 'world'
  end
end

Missing space after #.
Open

         #minute = Time.current.min .to_s
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cop checks whether comments have a leading space after the # denoting the start of the comment. The leading space is not required for some RDoc special syntax, like #++, #--, #:nodoc, =begin- and =end comments, "shebang" directives, or rackup options.

Example:

# bad
#Some comment

# good
# Some comment

Tab detected.
Open

    SPACE_TRACE_SPACE = "-"
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Tab detected.
Open

    ZERO = "0";
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Freeze mutable objects assigned to constants.
Open

    TWO_POINTS = ":"
Severity: Minor
Found in app/helpers/reader_helper.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

Use 2 (not 1) spaces for indentation.
Open

    TWO_POINTS = ":"
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cops checks for indentation that doesn't use the specified number of spaces.

See also the IndentationConsistency cop which is the companion to this one.

Example:

# bad
class A
 def test
  puts 'hello'
 end
end

# good
class A
  def test
    puts 'hello'
  end
end

Example: IgnoredPatterns: ['^\s*module']

# bad
module A
class B
  def test
  puts 'hello'
  end
end
end

# good
module A
class B
  def test
    puts 'hello'
  end
end
end

Don't use parentheses around the condition of an if.
Open

         if (month.length == SINGLE_CHAR)
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cop checks for the presence of superfluous parentheses around the condition of if/unless/while/until.

Example:

# bad
x += 1 while (x < 10)
foo unless (bar || baz)

if (x > 10)
elsif (x < 3)
end

# good
x += 1 while x < 10
foo unless bar || baz

if x > 10
elsif x < 3
end

Use snake_case for variable names.
Open

         correctDate = year + SPACE_TRACE_SPACE + month + SPACE_TRACE_SPACE + day 
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.

Example: EnforcedStyle: snake_case (default)

# bad
fooBar = 1

# good
foo_bar = 1

Example: EnforcedStyle: camelCase

# bad
foo_bar = 1

# good
fooBar = 1

Freeze mutable objects assigned to constants.
Open

    ZERO = "0";
Severity: Minor
Found in app/helpers/reader_helper.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

Tab detected.
Open

    
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

    TWO_POINTS = ":"
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Tab detected.
Open

         #hour = (Time.current.hour - ADJUSTING_FUSE_TO_BRAZILIAN).to_s
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Tab detected.
Open

         if (day.length == SINGLE_CHAR)
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Do not use semicolons to terminate expressions.
Open

    ZERO = "0";
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cop checks for multiple expressions placed on the same line. It also checks for lines terminated with a semicolon.

Example:

# bad
foo = 1; bar = 2;
baz = 3;

# good
foo = 1
bar = 2
baz = 3

Tab detected.
Open

         correctDate = year + SPACE_TRACE_SPACE + month + SPACE_TRACE_SPACE + day 
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Trailing whitespace detected.
Open

    
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Don't use parentheses around the condition of an if.
Open

         if (day.length == SINGLE_CHAR)
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cop checks for the presence of superfluous parentheses around the condition of if/unless/while/until.

Example:

# bad
x += 1 while (x < 10)
foo unless (bar || baz)

if (x > 10)
elsif (x < 3)
end

# good
x += 1 while x < 10
foo unless bar || baz

if x > 10
elsif x < 3
end

Extra blank line detected.
Open


    def mountCurrentDate() 
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cops checks for two or more consecutive blank lines.

Example:

# bad - It has two empty lines.
some_method
# one empty line
# two empty lines
some_method

# good
some_method
# one empty line
some_method

Trailing whitespace detected.
Open

    def mountCurrentDate() 
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Omit the parentheses in defs when the method doesn't accept any arguments.
Open

    def mountCurrentDate() 
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cop checks for parentheses in the definition of a method, that does not take any arguments. Both instance and class/singleton methods are checked.

Example:

# bad
def foo()
  # does a thing
end

# good
def foo
  # does a thing
end

# also good
def foo() does_a_thing end

Example:

# bad
def Baz.foo()
  # does a thing
end

# good
def Baz.foo
  # does a thing
end

Redundant return detected.
Open

        return correctDate.to_s
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Use 2 (not 1) spaces for indentation.
Open

             month = ZERO + month
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cops checks for indentation that doesn't use the specified number of spaces.

See also the IndentationConsistency cop which is the companion to this one.

Example:

# bad
class A
 def test
  puts 'hello'
 end
end

# good
class A
  def test
    puts 'hello'
  end
end

Example: IgnoredPatterns: ['^\s*module']

# bad
module A
class B
  def test
  puts 'hello'
  end
end
end

# good
module A
class B
  def test
    puts 'hello'
  end
end
end

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

    ZERO = "0";
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Tab detected.
Open

    
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Trailing whitespace detected.
Open

         year = Time.current.year.to_s 
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Tab detected.
Open

         end
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Freeze mutable objects assigned to constants.
Open

    DATE_SPACE = "/"
Severity: Minor
Found in app/helpers/reader_helper.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

Tab detected.
Open

         #minute = Time.current.min .to_s
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Tab detected.
Open

         if (month.length == SINGLE_CHAR)
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Tab detected.
Open

             month = ZERO + month
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Tab detected.
Open

         end
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
Open

         if (day.length == SINGLE_CHAR)
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

Example:

# bad
if condition
  do_stuff(bar)
end

unless qux.empty?
  Foo.do_something
end

# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

    SPACE_TRACE_SPACE = "-"
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Tab detected.
Open

         month = Time.current.month.to_s
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Missing space after #.
Open

         #hour = (Time.current.hour - ADJUSTING_FUSE_TO_BRAZILIAN).to_s
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cop checks whether comments have a leading space after the # denoting the start of the comment. The leading space is not required for some RDoc special syntax, like #++, #--, #:nodoc, =begin- and =end comments, "shebang" directives, or rackup options.

Example:

# bad
#Some comment

# good
# Some comment

Tab detected.
Open

    TWO_POINTS = ":"
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Tab detected.
Open

         day = Time.current.day.to_s
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Trailing whitespace detected.
Open

    
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Use snake_case for method names.
Open

    def mountCurrentDate() 
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cop makes sure that all methods use the configured style, snake_case or camelCase, for their names.

Example: EnforcedStyle: snake_case (default)

# bad
def fooBar; end

# good
def foo_bar; end

Example: EnforcedStyle: camelCase

# bad
def foo_bar; end

# good
def fooBar; end

Freeze mutable objects assigned to constants.
Open

    SPACE_TRACE_SPACE = "-"
Severity: Minor
Found in app/helpers/reader_helper.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

Do not use semicolons to terminate expressions.
Open

    ADJUSTING_FUSE_TO_BRAZILIAN = 3;
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cop checks for multiple expressions placed on the same line. It also checks for lines terminated with a semicolon.

Example:

# bad
foo = 1; bar = 2;
baz = 3;

# good
foo = 1
bar = 2
baz = 3

Use 2 (not 1) spaces for indentation.
Open

             day = ZERO + day
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

This cops checks for indentation that doesn't use the specified number of spaces.

See also the IndentationConsistency cop which is the companion to this one.

Example:

# bad
class A
 def test
  puts 'hello'
 end
end

# good
class A
  def test
    puts 'hello'
  end
end

Example: IgnoredPatterns: ['^\s*module']

# bad
module A
class B
  def test
  puts 'hello'
  end
end
end

# good
module A
class B
  def test
    puts 'hello'
  end
end
end

Tab detected.
Open

    ADJUSTING_FUSE_TO_BRAZILIAN = 3;
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Tab detected.
Open

    SINGLE_CHAR = 1
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Tab detected.
Open

    def mountCurrentDate() 
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Trailing whitespace detected.
Open

         correctDate = year + SPACE_TRACE_SPACE + month + SPACE_TRACE_SPACE + day 
Severity: Minor
Found in app/helpers/reader_helper.rb by rubocop

Missing top-level module documentation comment.
Open

module ReaderHelper
Severity: Minor
Found in app/helpers/reader_helper.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