| 1 | <?php namespace Bedard\Shop\FormWidgets; |
||
| 9 | class DriverConfig extends FormWidgetBase |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * {@inheritdoc} |
||
| 13 | */ |
||
| 14 | protected $defaultAlias = 'bedard_shop_driver_config'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var \Bedard\Shop\Classes\DriverManager; |
||
| 18 | */ |
||
| 19 | protected $manager; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * {@inheritdoc} |
||
| 23 | */ |
||
| 24 | public function init() |
||
| 28 | |||
| 29 | /** |
||
| 30 | * {@inheritdoc} |
||
| 31 | */ |
||
| 32 | public function render() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Prepares the form widget view data. |
||
| 41 | */ |
||
| 42 | public function prepareVars() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritdoc} |
||
| 49 | */ |
||
| 50 | public function loadAssets() |
||
| 55 | |||
| 56 | /** |
||
| 57 | * {@inheritdoc} |
||
| 58 | */ |
||
| 59 | public function getSaveValue($value) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Get the driver details. |
||
| 66 | * |
||
| 67 | * @return array |
||
| 68 | */ |
||
| 69 | protected function getShippingDriverDetails() |
||
| 77 | } |
||
| 78 |
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.