Sha256: b2ff4a264fd95192cf4058292b9807f4f43759cd1ed6cd0a2a050c943e62b5f5

Contents?: true

Size: 1.87 KB

Versions: 53

Compression:

Stored size: 1.87 KB

Contents

# Too Many Statements

## Introduction

A method with _Too Many Statements_ is any method that has a large number of lines.

## Current Support in Reek

_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:

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

## Configuration

Reek's _Too Many Statements_ detector supports the [Basic Smell Options](Basic-Smell-Options.md), plus:

| Option         | Value       | Effect  |
| ---------------|-------------|---------|
| `max_statements` |  integer | The maximum number of statements allowed in a method before a warning is issued. Defaults to 5. |

_Too Many Statements_'s default configuration is:

```yaml
---
TooManyStatements:
  enabled: true
  exclude:
  - initialize
  max_statements: 5
```

By default, `initialize` is not checked for length; any class's constructor can be as long as necessary.

Version data entries

53 entries across 51 versions & 2 rubygems

Version Path
reek-4.8.2 docs/Too-Many-Statements.md
reek-4.8.1 docs/Too-Many-Statements.md
reek-4.8.0 docs/Too-Many-Statements.md
reek-4.7.3 docs/Too-Many-Statements.md
reek-4.7.2 docs/Too-Many-Statements.md
reek-4.7.1 docs/Too-Many-Statements.md
reek-4.7.0 docs/Too-Many-Statements.md
reek-4.6.2 docs/Too-Many-Statements.md
reek-4.6.1 docs/Too-Many-Statements.md
reek-4.6.0 docs/Too-Many-Statements.md
reek-4.5.6 docs/Too-Many-Statements.md
reek-4.5.5 docs/Too-Many-Statements.md
reek-4.5.4 docs/Too-Many-Statements.md
reek-4.5.3 docs/Too-Many-Statements.md
reek-4.5.2 docs/Too-Many-Statements.md
reek-4.5.1 docs/Too-Many-Statements.md
reek-4.5.0 docs/Too-Many-Statements.md
reek-4.4.2 docs/Too-Many-Statements.md
reek-4.4.1 docs/Too-Many-Statements.md
reek-4.4.0 docs/Too-Many-Statements.md