| Conditions | 13 |
| Paths | 13 |
| Total Lines | 33 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 22 |
| CRAP Score | 13 |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 23 | 5 | public function make($operator, $key = null, $reference = null) |
|
| 24 | { |
||
| 25 | switch ($operator) { |
||
| 26 | // Leaf expressions |
||
| 27 | 5 | case Type::EQ: |
|
| 28 | 5 | case Type::GT: |
|
| 29 | 5 | case Type::GTE: |
|
| 30 | 5 | case Type::LT: |
|
| 31 | 5 | case Type::LTE: |
|
| 32 | 5 | case Type::IN: |
|
| 33 | 5 | case Type::REGEX: |
|
| 34 | 1 | $class = $this->classFromOperator('Leaf', $operator); |
|
| 35 | |||
| 36 | 1 | return new $class($key, $reference); |
|
| 37 | |||
| 38 | // Tree expressions |
||
| 39 | 4 | case Type::AND_MATCH: |
|
| 40 | 4 | case Type::OR_MATCH: |
|
| 41 | 4 | case Type::NOT: |
|
| 42 | 1 | $class = $this->classFromOperator('Tree', $operator); |
|
| 43 | |||
| 44 | 1 | return new $class(); |
|
| 45 | |||
| 46 | // Negations |
||
| 47 | 3 | case Type::NE: |
|
| 48 | 1 | return new NotExpression([new EqExpression($key, $reference)]); |
|
| 49 | 2 | case Type::NIN: |
|
| 50 | 1 | return new NotExpression([new InExpression($key, $reference)]); |
|
| 51 | |||
| 52 | 1 | default: |
|
| 53 | 1 | throw new \Exception("Unknown operator `$operator`."); |
|
| 54 | 1 | } |
|
| 55 | } |
||
| 56 | |||
| 67 |