MatteoRagni/cas-rb

View on GitHub
lib/operators/bary-op.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Method has too many lines. [14/10]
Open

    def subs_lhs(dt)
      CAS::Help.assert(dt, Hash)
      sub = dt.keys.select { |e| e == @x }[0]
      if sub
        if dt[sub].is_a? CAS::Op
Severity: Minor
Found in lib/operators/bary-op.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 has too many lines. [14/10]
Open

    def subs_rhs(dt)
      CAS::Help.assert(dt, Hash)
      sub = dt.keys.select { |e| e == @y }[0]
      if sub
        if dt[sub].is_a? CAS::Op
Severity: Minor
Found in lib/operators/bary-op.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.

Assignment Branch Condition size for subs_lhs is too high. [17.52/15]
Open

    def subs_lhs(dt)
      CAS::Help.assert(dt, Hash)
      sub = dt.keys.select { |e| e == @x }[0]
      if sub
        if dt[sub].is_a? CAS::Op
Severity: Minor
Found in lib/operators/bary-op.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

Assignment Branch Condition size for subs_rhs is too high. [17.52/15]
Open

    def subs_rhs(dt)
      CAS::Help.assert(dt, Hash)
      sub = dt.keys.select { |e| e == @y }[0]
      if sub
        if dt[sub].is_a? CAS::Op
Severity: Minor
Found in lib/operators/bary-op.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. [12/10]
Open

    def simplify
      hash = @x.to_s
      @x = @x.simplify
      while @x.to_s != hash
        hash = @x.to_s
Severity: Minor
Found in lib/operators/bary-op.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 subs_lhs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def subs_lhs(dt)
      CAS::Help.assert(dt, Hash)
      sub = dt.keys.select { |e| e == @x }[0]
      if sub
        if dt[sub].is_a? CAS::Op
Severity: Minor
Found in lib/operators/bary-op.rb - About 25 mins 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

Method subs_rhs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def subs_rhs(dt)
      CAS::Help.assert(dt, Hash)
      sub = dt.keys.select { |e| e == @y }[0]
      if sub
        if dt[sub].is_a? CAS::Op
Severity: Minor
Found in lib/operators/bary-op.rb - About 25 mins 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

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

    def subs_rhs(dt)
      CAS::Help.assert(dt, Hash)
      sub = dt.keys.select { |e| e == @y }[0]
      if sub
        if dt[sub].is_a? CAS::Op
Severity: Major
Found in lib/operators/bary-op.rb and 1 other location - About 1 hr to fix
lib/operators/bary-op.rb on lines 103..117

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

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 subs_lhs(dt)
      CAS::Help.assert(dt, Hash)
      sub = dt.keys.select { |e| e == @x }[0]
      if sub
        if dt[sub].is_a? CAS::Op
Severity: Major
Found in lib/operators/bary-op.rb and 1 other location - About 1 hr to fix
lib/operators/bary-op.rb on lines 124..138

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

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. [85/80]
Open

          raise CASError, "Impossible subs. Received a #{dt[sub].class} = #{dt[sub]}"
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

When defining the == operator, name its argument other.
Open

    def ==(op)
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

This cop makes sure that certain binary operator methods have their sole parameter named other.

Example:

# bad
def +(amount); end

# good
def +(other); end

Missing top-level module documentation comment.
Open

module CAS
Severity: Minor
Found in lib/operators/bary-op.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

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

      if y.is_a? Numeric
Severity: Minor
Found in lib/operators/bary-op.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?

Line is too long. [107/80]
Open

    #  * **argument**: `CAS::Op` right argument of the node or `Numeric` to be converted in `CAS::Constant`
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

Use || instead of or.
Open

      @x.depend? v or @y.depend? v
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

Example: EnforcedStyle: always (default)

# bad
foo.save and return

# bad
if foo and bar
end

# good
foo.save && return

# good
if foo && bar
end

Example: EnforcedStyle: conditionals

# bad
if foo and bar
end

# good
foo.save && return

# good
foo.save and return

# good
if foo && bar
end

Do not place comments on the same line as the end keyword.
Open

  end # BinaryOp
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

This cop checks for comments put on the same line as some keywords. These keywords are: begin, class, def, end, module.

Note that some comments (such as :nodoc: and rubocop:disable) are allowed.

Example:

# bad
if condition
  statement
end # end if

# bad
class X # comment
  statement
end

# bad
def x; end # comment

# good
if condition
  statement
end

# good
class X # :nodoc:
  y
end

Redundant return detected. To return multiple values, use an array.
Open

      return left, right
Severity: Minor
Found in lib/operators/bary-op.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.

Redundant return detected.
Open

      return self
Severity: Minor
Found in lib/operators/bary-op.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.

Redundant self detected.
Open

      return self.subs_lhs(dt).subs_rhs(dt)
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

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

      raise CAS::CASError, "Not implemented. This is a virtual method"
Severity: Minor
Found in lib/operators/bary-op.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"

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

      if op.is_a? CAS::BinaryOp
Severity: Minor
Found in lib/operators/bary-op.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

Line is too long. [106/80]
Open

    #  * **argument**: `CAS::Op` left argument of the node or `Numeric` to be converted in `CAS::Constant`
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

Line is too long. [85/80]
Open

          raise CASError, "Impossible subs. Received a #{dt[sub].class} = #{dt[sub]}"
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

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

      raise CAS::CASError, "Not Implemented. This is a virtual method"
Severity: Minor
Found in lib/operators/bary-op.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"

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

      if x.is_a? Numeric
Severity: Minor
Found in lib/operators/bary-op.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?

Redundant return detected.
Open

      return self.subs_lhs(dt).subs_rhs(dt)
Severity: Minor
Found in lib/operators/bary-op.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 && instead of and.
Open

        return (self.class == op.class and @x == op.x and @y == op.y)
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

Example: EnforcedStyle: always (default)

# bad
foo.save and return

# bad
if foo and bar
end

# good
foo.save && return

# good
if foo && bar
end

Example: EnforcedStyle: conditionals

# bad
if foo and bar
end

# good
foo.save && return

# good
foo.save and return

# good
if foo && bar
end

Redundant return detected.
Open

      return self
Severity: Minor
Found in lib/operators/bary-op.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.

Do not use :: for method calls.
Open

          @x = CAS::const dt[sub]
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

This cop checks for methods invoked via the :: operator instead of the . operator (like FileUtils::rmdir instead of FileUtils.rmdir).

Example:

# bad
Timeout::timeout(500) { do_something }
FileUtils::rmdir(dir)
Marshal::dump(obj)

# good
Timeout.timeout(500) { do_something }
FileUtils.rmdir(dir)
Marshal.dump(obj)

Script file bary-op.rb doesn't have execute permission.
Open

#!/usr/bin/env ruby
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

Use && instead of and.
Open

        return (self.class == op.class and @x == op.x and @y == op.y)
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

Example: EnforcedStyle: always (default)

# bad
foo.save and return

# bad
if foo and bar
end

# good
foo.save && return

# good
if foo && bar
end

Example: EnforcedStyle: conditionals

# bad
if foo and bar
end

# good
foo.save && return

# good
foo.save and return

# good
if foo && bar
end

Line is too long. [86/80]
Open

    #  * **returns**: `Array` of differentiated branches ([0] for left, [1] for right)
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

Do not use :: for method calls.
Open

          @y = CAS::const dt[sub]
Severity: Minor
Found in lib/operators/bary-op.rb by rubocop

This cop checks for methods invoked via the :: operator instead of the . operator (like FileUtils::rmdir instead of FileUtils.rmdir).

Example:

# bad
Timeout::timeout(500) { do_something }
FileUtils::rmdir(dir)
Marshal::dump(obj)

# good
Timeout.timeout(500) { do_something }
FileUtils.rmdir(dir)
Marshal.dump(obj)

Do not use parallel assignment.
Open

      left, right = CAS::Zero, CAS::Zero
Severity: Minor
Found in lib/operators/bary-op.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

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

      raise CAS::CASError, "Not Implemented. This is a virtual method"
Severity: Minor
Found in lib/operators/bary-op.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"

There are no issues that match your filters.

Category
Status