| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 30 |
| CRAP Score | 1 |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 7 | 24 | public function __construct() |
|
| 8 | { |
||
| 9 | $this->container += [ |
||
| 10 | '+' => function() { |
||
| 11 | 9 | return array_sum(func_get_arg(0)); |
|
| 12 | 24 | }, |
|
| 13 | '-' => function() { |
||
| 14 | 6 | list($first, $second) = func_get_arg(0); // array [5, 3] |
|
| 15 | 6 | return $first - $second; |
|
| 16 | 24 | }, |
|
| 17 | '*' => function() { |
||
| 18 | 6 | return array_product(func_get_arg(0)); |
|
| 19 | 24 | }, |
|
| 20 | '/' => function() { |
||
| 21 | 3 | return func_get_arg(0)[0] / func_get_arg(0)[1]; |
|
| 22 | 24 | }, |
|
| 23 | '>' => function() { |
||
| 24 | 9 | return func_get_arg(0)[0] > func_get_arg(0)[1]; |
|
| 25 | 24 | }, |
|
| 26 | '>=' => function() { |
||
| 27 | return func_get_arg(0)[0] >= func_get_arg(0)[1]; |
||
| 28 | 24 | }, |
|
| 29 | '<' => function() { |
||
| 30 | 3 | return func_get_arg(0)[0] < func_get_arg(0)[1]; |
|
| 31 | 24 | }, |
|
| 32 | '<=' => function() { |
||
| 33 | return func_get_arg(0)[0] <= func_get_arg(0)[1]; |
||
| 34 | 24 | }, |
|
| 35 | '=' => function() { |
||
| 36 | return func_get_arg(0)[0] == func_get_arg(0)[1]; |
||
| 37 | 24 | }, |
|
| 38 | 'abs' => function() { |
||
| 39 | return abs(func_get_arg(0)); |
||
| 40 | 24 | }, |
|
| 41 | 'not' => function() { |
||
| 42 | return !func_get_arg(0); |
||
| 43 | 24 | }, |
|
| 44 | 'first' => function() { |
||
| 45 | return func_get_arg(0)[0][0]; |
||
| 46 | 24 | }, |
|
| 47 | 'list' => function() { |
||
| 48 | return func_get_args()[0]; |
||
| 49 | 24 | }, |
|
| 50 | 'eq?' => function() { |
||
| 51 | return func_get_arg(0)[0] == func_get_arg(0)[1]; |
||
| 52 | 24 | }, |
|
| 53 | 'number?' => function() { |
||
| 54 | return is_numeric(func_get_arg(0)); |
||
| 55 | 24 | }, |
|
| 56 | 'quote' => function() { |
||
| 57 | 6 | return implode(' ', func_get_arg(0)); |
|
| 58 | 24 | }, |
|
| 59 | 24 | 'define' => function() { |
|
| 60 | 3 | list($name, $value) = func_get_arg(0); |
|
| 61 | 3 | $this[$name] = $value; |
|
| 62 | 24 | }, |
|
| 63 | ]; |
||
| 64 | 24 | } |
|
| 65 | } |
||
| 66 |