dvinciguerra/business-br

View on GitHub

Showing 123 of 123 total issues

Assignment Branch Condition size for validate is too high. [29.75/15]
Open

    def validate(cnpj)
      return false unless cnpj
      return false unless cnpj.length == 14 || cnpj.length == 18
      return false unless cnpj =~ %r{^\d{2}\.?\d{3}\.?\d{3}/?\d{4}-?\d{2}$}

Severity: Minor
Found in lib/business-br/cnpj.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 validate is too high. [28.46/15]
Open

    def validate(cpf)
      return false unless cpf
      return false unless cpf.length == 11 || cpf.length == 14
      return false unless cpf =~ /^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/

Severity: Minor
Found in lib/business-br/cpf.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. [19/10]
Open

    def validate(cpf)
      return false unless cpf
      return false unless cpf.length == 11 || cpf.length == 14
      return false unless cpf =~ /^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/

Severity: Minor
Found in lib/business-br/cpf.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. [19/10]
Open

    def validate(cnpj)
      return false unless cnpj
      return false unless cnpj.length == 14 || cnpj.length == 18
      return false unless cnpj =~ %r{^\d{2}\.?\d{3}\.?\d{3}/?\d{4}-?\d{2}$}

Severity: Minor
Found in lib/business-br/cnpj.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.

Complex method Business::BR::CNPJ#validate (44.8)
Open

    def validate(cnpj)
      return false unless cnpj
      return false unless cnpj.length == 14 || cnpj.length == 18
      return false unless cnpj =~ %r{^\d{2}\.?\d{3}\.?\d{3}/?\d{4}-?\d{2}$}

Severity: Minor
Found in lib/business-br/cnpj.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Cyclomatic complexity for validate is too high. [9/6]
Open

    def validate(cnpj)
      return false unless cnpj
      return false unless cnpj.length == 14 || cnpj.length == 18
      return false unless cnpj =~ %r{^\d{2}\.?\d{3}\.?\d{3}/?\d{4}-?\d{2}$}

Severity: Minor
Found in lib/business-br/cnpj.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.

Cyclomatic complexity for validate is too high. [9/6]
Open

    def validate(cpf)
      return false unless cpf
      return false unless cpf.length == 11 || cpf.length == 14
      return false unless cpf =~ /^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/

Severity: Minor
Found in lib/business-br/cpf.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. [12/10]
Open

          def parse_response(response)
            json = decode_json(response)
            create_entity(
              json, extract: {
                zipcode: @zipcode,

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.

Perceived complexity for validate is too high. [9/7]
Open

    def validate(cpf)
      return false unless cpf
      return false unless cpf.length == 11 || cpf.length == 14
      return false unless cpf =~ /^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/

Severity: Minor
Found in lib/business-br/cpf.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

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

          def parse_response(response)
            json = JSON.parse(response, symbolize_names: true)
            create_entity(
              json, extract: {
                zipcode: :cep,

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.

Perceived complexity for validate is too high. [9/7]
Open

    def validate(cnpj)
      return false unless cnpj
      return false unless cnpj.length == 14 || cnpj.length == 18
      return false unless cnpj =~ %r{^\d{2}\.?\d{3}\.?\d{3}/?\d{4}-?\d{2}$}

Severity: Minor
Found in lib/business-br/cnpj.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Complex method Business::BR::CPF#validate (38.2)
Open

    def validate(cpf)
      return false unless cpf
      return false unless cpf.length == 11 || cpf.length == 14
      return false unless cpf =~ /^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/

Severity: Minor
Found in lib/business-br/cpf.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Method validate has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def validate(cnpj)
      return false unless cnpj
      return false unless cnpj.length == 14 || cnpj.length == 18
      return false unless cnpj =~ %r{^\d{2}\.?\d{3}\.?\d{3}/?\d{4}-?\d{2}$}

Severity: Minor
Found in lib/business-br/cnpj.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

Method validate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def validate(cpf)
      return false unless cpf
      return false unless cpf.length == 11 || cpf.length == 14
      return false unless cpf =~ /^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/

Severity: Minor
Found in lib/business-br/cpf.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

Business::BR::CEP#initialize is controlled by argument 'opts'
Open

      @opts = opts || {}
Severity: Minor
Found in lib/business-br/cep.rb by reek

Control Parameter is a special case of Control Couple

Example

A simple example would be the "quoted" parameter in the following method:

def write(quoted)
  if quoted
    write_quoted @value
  else
    write_unquoted @value
  end
end

Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

Business::BR::CEP#type has approx 7 statements
Open

    def type(cep)
Severity: Minor
Found in lib/business-br/cep.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.)

Business::BR::CPF#format is controlled by argument 'cpf'
Open

      if cpf =~ /^(\d{3})\.?(\d{3})\.?(\d{3})-?(\d{2})$/
Severity: Minor
Found in lib/business-br/cpf.rb by reek

Control Parameter is a special case of Control Couple

Example

A simple example would be the "quoted" parameter in the following method:

def write(quoted)
  if quoted
    write_quoted @value
  else
    write_unquoted @value
  end
end

Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

Business::BR::CEP::Providers::Base#create_entity has approx 7 statements
Open

          def create_entity(json, extract: {})
Severity: Minor
Found in lib/business-br/cep/providers/base.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.)

Business::BR::CEP::Providers::Postmon#search_by has approx 6 statements
Open

          def search_by(cep)

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

Business::BR::CEP::Providers::RepublicaVirtual#search_by has approx 6 statements
Open

          def search_by(cep)

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

Severity
Category
Status
Source
Language