CoolElvis/gt06_server

View on GitHub
lib/gt06_server/protocol.rb

Summary

Maintainability
A
0 mins
Test Coverage

Gt06Server::Protocol#acknowledgment_pack_for calls 'pack.payload' 2 times
Open

      ack_pack.protocol_number = pack.payload.protocol_number
      ack_pack.serial_number = pack.payload.serial_number
Severity: Minor
Found in lib/gt06_server/protocol.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.

Gt06Server::Protocol has no descriptive comment
Open

  module Protocol
Severity: Minor
Found in lib/gt06_server/protocol.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

Gt06Server::Protocol#command_pack has unused parameter 'command'
Open

    def command_pack(command)
Severity: Minor
Found in lib/gt06_server/protocol.rb by reek

Unused Parameter refers to methods with parameters that are unused in scope of the method.

Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.

Example

Given:

class Klass
  def unused_parameters(x,y,z)
    puts x,y # but not z
  end
end

Reek would emit the following warning:

[2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)

TODO found
Open

    # TODO
Severity: Minor
Found in lib/gt06_server/protocol.rb by fixme

Put empty method definitions on a single line.
Open

    def command_pack(command)
    end
Severity: Minor
Found in lib/gt06_server/protocol.rb by rubocop

This cop checks for the formatting of empty method definitions. By default it enforces empty method definitions to go on a single line (compact style), but it can be configured to enforce the end to go on its own line (expanded style).

Note: A method definition is not considered empty if it contains comments.

Example: EnforcedStyle: compact (default)

# bad
def foo(bar)
end

def self.foo(bar)
end

# good
def foo(bar); end

def foo(bar)
  # baz
end

def self.foo(bar); end

Example: EnforcedStyle: expanded

# bad
def foo(bar); end

def self.foo(bar); end

# good
def foo(bar)
end

def self.foo(bar)
end

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

      if [:login_message, :status_information].include?(pack.payload.message_type.to_sym)
Severity: Minor
Found in lib/gt06_server/protocol.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?

Use %i or %I for an array of symbols.
Open

      if [:login_message, :status_information].include?(pack.payload.message_type.to_sym)
Severity: Minor
Found in lib/gt06_server/protocol.rb by rubocop

This cop can check for array literals made up of symbols that are not using the %i() syntax.

Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

Example: EnforcedStyle: percent (default)

# good
%i[foo bar baz]

# bad
[:foo, :bar, :baz]

Example: EnforcedStyle: brackets

# good
[:foo, :bar, :baz]

# bad
%i[foo bar baz]

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

      if [:login_message, :status_information].include?(pack.payload.message_type.to_sym)
Severity: Minor
Found in lib/gt06_server/protocol.rb by rubocop

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

There are no issues that match your filters.

Category
Status