| Conditions | 2 |
| Paths | 2 |
| Total Lines | 56 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 19 | public function init($params) |
||
| 20 | { |
||
| 21 | $nbObjects = $params['nb_objects']; |
||
| 22 | |||
| 23 | $objects = []; |
||
| 24 | for ($i = 0; $i < $nbObjects; $i++) { |
||
| 25 | $objects[] = new Article('hello', $i); |
||
| 26 | } |
||
| 27 | |||
| 28 | $container = $this->createContainer([ |
||
| 29 | 'mapping' => [ |
||
| 30 | Article::class => [ |
||
| 31 | 'grids' => [ |
||
| 32 | 'main' => [ |
||
| 33 | 'columns' => [ |
||
| 34 | 'title' => [ |
||
| 35 | 'type' => 'property', |
||
| 36 | ], |
||
| 37 | 'number' => [ |
||
| 38 | 'type' => 'property', |
||
| 39 | ], |
||
| 40 | ], |
||
| 41 | 'filters' => [ |
||
| 42 | 'title' => [ |
||
| 43 | 'type' => 'string', |
||
| 44 | ], |
||
| 45 | ], |
||
| 46 | ], |
||
| 47 | 'form' => [ |
||
| 48 | 'columns' => [ |
||
| 49 | 'select' => [ |
||
| 50 | 'type' => 'select', |
||
| 51 | ], |
||
| 52 | 'title' => [ |
||
| 53 | 'type' => 'property', |
||
| 54 | ], |
||
| 55 | 'number' => [ |
||
| 56 | 'type' => 'property', |
||
| 57 | ], |
||
| 58 | ], |
||
| 59 | 'filters' => [ |
||
| 60 | 'title' => [ |
||
| 61 | 'type' => 'string', |
||
| 62 | ], |
||
| 63 | ], |
||
| 64 | ], |
||
| 65 | ], |
||
| 66 | ], |
||
| 67 | ], |
||
| 68 | 'collections' => [ |
||
| 69 | Article::class => $objects, |
||
| 70 | ], |
||
| 71 | ]); |
||
| 72 | |||
| 73 | $this->factory = $container->get('grid.factory'); |
||
| 74 | } |
||
| 75 | |||
| 109 |