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