| Conditions | 2 |
| Paths | 2 |
| Total Lines | 36 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | public function setUp() |
||
| 19 | { |
||
| 20 | $nbObjects = 100; |
||
| 21 | for ($i = 0; $i < $nbObjects; $i++) { |
||
| 22 | $objects[] = new Article('hello', $i); |
||
|
|
|||
| 23 | } |
||
| 24 | |||
| 25 | $container = $this->createContainer([ |
||
| 26 | 'mapping' => [ |
||
| 27 | Article::class => [ |
||
| 28 | 'grids' => [ |
||
| 29 | 'main' => [ |
||
| 30 | 'columns' => [ |
||
| 31 | 'title' => [ |
||
| 32 | 'type' => 'property', |
||
| 33 | ], |
||
| 34 | 'number' => [ |
||
| 35 | 'type' => 'property', |
||
| 36 | ], |
||
| 37 | ], |
||
| 38 | 'filters' => [ |
||
| 39 | 'title' => [ |
||
| 40 | 'type' => 'string', |
||
| 41 | ], |
||
| 42 | ], |
||
| 43 | ], |
||
| 44 | ], |
||
| 45 | ], |
||
| 46 | ], |
||
| 47 | 'collections' => [ |
||
| 48 | Article::class => $objects |
||
| 49 | ], |
||
| 50 | ]); |
||
| 51 | |||
| 52 | $this->factory = $container->get('grid.factory'); |
||
| 53 | } |
||
| 54 | |||
| 65 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.