MatteoRagni/cas-rb

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

Summary

Maintainability
A
1 hr
Test Coverage

Class has too many lines. [104/100]
Open

  class NaryOp < CAS::Op
    # List of arguments of the operation
    attr_reader :x

    # Initialize a new empty N-elements operation container. This is
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

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

    def subs(dt)
      CAS::Help.assert(dt, Hash)
      @x = @x.map { |z| z.subs(dt) || z }
      @x.each_with_index do |x, k|
        sub = dt.keys.select { |e| e == x }[0]
Severity: Minor
Found in lib/operators/nary-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 is too high. [19.82/15]
Open

    def subs(dt)
      CAS::Help.assert(dt, Hash)
      @x = @x.map { |z| z.subs(dt) || z }
      @x.each_with_index do |x, k|
        sub = dt.keys.select { |e| e == x }[0]
Severity: Minor
Found in lib/operators/nary-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. [13/10]
Open

    def __reduce_multeplicity(xs)
      count = Hash.new(0)
      xs.each do |x|
        e = x
        count.keys.each { |d| e = d if x == d  }
Severity: Minor
Found in lib/operators/nary-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 has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def subs(dt)
      CAS::Help.assert(dt, Hash)
      @x = @x.map { |z| z.subs(dt) || z }
      @x.each_with_index do |x, k|
        sub = dt.keys.select { |e| e == x }[0]
Severity: Minor
Found in lib/operators/nary-op.rb - About 45 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 __reduce_multeplicity has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def __reduce_multeplicity(xs)
      count = Hash.new(0)
      xs.each do |x|
        e = x
        count.keys.each { |d| e = d if x == d  }
Severity: Minor
Found in lib/operators/nary-op.rb - About 35 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 == has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def ==(op)
      # CAS::Help.assert(op, CAS::Op)
      if op.is_a? CAS::NaryOp
        return false if @x.size != op.x.size
        0.upto(@x.size - 1) do |i|
Severity: Minor
Found in lib/operators/nary-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

Use each_key instead of keys.each.
Open

        count.keys.each { |d| e = d if x == d  }
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

This cop checks for uses of each_key and each_value Hash methods.

Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

Example:

# bad
hash.keys.each { |k| p k }
hash.values.each { |v| p v }
hash.each { |k, _v| p k }
hash.each { |_k, v| p v }

# good
hash.each_key { |k| p k }
hash.each_value { |v| p v }

Line is too long. [91/80]
Open

    # * **block**: yields an `Array` of `CAS::Constant` and an `Array` of others `CAS::Op`,
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

Use !empty? instead of size > 0.
Open

      if const.size > 0
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.

Example:

# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0

# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?

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

  end # NaryOp
Severity: Minor
Found in lib/operators/nary-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

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/nary-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?

Prefer single-quoted strings inside interpolations.
Open

      return "(#{@x.map(&:to_code).join(", ")})"
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

This cop checks that quotes inside the string interpolation match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
result = "Tests #{success ? "PASS" : "FAIL"}"

# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"

Example: EnforcedStyle: double_quotes

# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"

# good
result = "Tests #{success ? "PASS" : "FAIL"}"

Extra empty line detected at class body end.
Open


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

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

Example: EnforcedStyle: empty_lines

# good

class Foo

  def bar
    # ...
  end

end

Example: EnforcedStyle: emptylinesexcept_namespace

# good

class Foo
  class Bar

    # ...

  end
end

Example: EnforcedStyle: emptylinesspecial

# good
class Foo

  def bar; end

end

Example: EnforcedStyle: noemptylines (default)

# good

class Foo
  def bar
    # ...
  end
end

Line is too long. [81/80]
Open

    #  * **block**: yields the count and the op. Get the value to insert in a new
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

Redundant return detected.
Open

      return CAS::Zero
Severity: Minor
Found in lib/operators/nary-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.

Line is too long. [88/80]
Open

    # of the sum and will reduce their multeplicity. A block can be used to do something
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

Redundant self detected.
Open

      while self.to_s != hash
Severity: Minor
Found in lib/operators/nary-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

Unnecessary spacing detected.
Open

        count.keys.each { |d| e = d if x == d  }
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

This cop checks for extra/unnecessary whitespace.

Example:

# good if AllowForAlignment is true
name      = "RuboCop"
# Some comment and an empty line

website  += "/bbatsov/rubocop" unless cond
puts        "rubocop"          if     debug

# bad for any configuration
set_app("RuboCop")
website  = "https://github.com/bbatsov/rubocop"

Line is too long. [89/80]
Open

    #  * **returns**: `String` that represent Ruby code to be parsed in `CAS::Op#to_proc`
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

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

    def ==(op)
Severity: Minor
Found in lib/operators/nary-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

Redundant return detected.
Open

      return ret
Severity: Minor
Found in lib/operators/nary-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.

Missing top-level module documentation comment.
Open

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

Prefer single-quoted strings inside interpolations.
Open

      "#{self.class}(#{@x.map(&:inspect).join(", ")})"
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

This cop checks that quotes inside the string interpolation match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
result = "Tests #{success ? "PASS" : "FAIL"}"

# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"

Example: EnforcedStyle: double_quotes

# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"

# good
result = "Tests #{success ? "PASS" : "FAIL"}"

Redundant return detected.
Open

      return r.uniq
Severity: Minor
Found in lib/operators/nary-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.

Pass &:simplify as an argument to map instead of a block.
Open

      @x = @x.map { |x| x.simplify }
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

Use symbols as procs when possible.

Example:

# bad
something.map { |s| s.upcase }

# good
something.map(&:upcase)

Line is too long. [81/80]
Open

    # Reduce multeplicity will scan for elements that are equal in the definition
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

Do not use :: for method calls.
Open

            @x[k] = CAS::const dt[sub]
Severity: Minor
Found in lib/operators/nary-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)

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

      if self.depend?(v)
Severity: Minor
Found in lib/operators/nary-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 @x.map { |x| x.call(fd) }
Severity: Minor
Found in lib/operators/nary-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.

Line is too long. [92/80]
Open

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

Redundant return detected.
Open

      return "(#{@x.map(&:to_s).join(", ")})"
Severity: Minor
Found in lib/operators/nary-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

      if self.depend?(v)
Severity: Minor
Found in lib/operators/nary-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

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

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

Line is too long. [97/80]
Open

    #  * **argument**: `Numeric` to be converted in `CAS::Constant` or `CAS::Op` child operations
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

Redundant return detected.
Open

      return "(#{@x.map(&:to_code).join(", ")})"
Severity: Minor
Found in lib/operators/nary-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/nary-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.

Pass &:simplify as an argument to map instead of a block.
Open

        @x = @x.map { |x| x.simplify }
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

Use symbols as procs when possible.

Example:

# bad
something.map { |s| s.upcase }

# good
something.map(&:upcase)

Redundant self detected.
Open

      hash = self.to_s
Severity: Minor
Found in lib/operators/nary-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

Redundant self detected.
Open

        hash = self.to_s
Severity: Minor
Found in lib/operators/nary-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 inside interpolations.
Open

      return "(#{@x.map(&:to_s).join(", ")})"
Severity: Minor
Found in lib/operators/nary-op.rb by rubocop

This cop checks that quotes inside the string interpolation match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
result = "Tests #{success ? "PASS" : "FAIL"}"

# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"

Example: EnforcedStyle: double_quotes

# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"

# good
result = "Tests #{success ? "PASS" : "FAIL"}"

There are no issues that match your filters.

Category
Status