1 | <?php |
||
15 | class UpdateSettingsTo570 extends Migration |
||
16 | { |
||
17 | const PREVIOUS_FONTAWESOME_LINK = "https://use.fontawesome.com/releases/v5.6.3/css/all.css"; |
||
18 | const PREVIOUS_FONTAWESOME_LINK_ATTRIBUTES = [ |
||
19 | [ |
||
20 | 'attribute' => 'integrity', |
||
21 | 'value' => 'sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/' |
||
22 | ], |
||
23 | [ |
||
24 | 'attribute' => 'crossorigin', |
||
25 | 'value' => 'anonymous' |
||
26 | ] |
||
27 | ]; |
||
28 | |||
29 | const NEW_FONTAWESOME_LINK = 'https://use.fontawesome.com/releases/v5.7.0/css/all.css'; |
||
30 | const NEW_FONTAWESOME_LINK_ATTRIBUTES = [ |
||
31 | [ |
||
32 | 'attribute' => 'integrity', |
||
33 | 'value' => 'sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ' |
||
34 | ], |
||
35 | [ |
||
36 | 'attribute' => 'crossorigin', |
||
37 | 'value' => 'anonymous' |
||
38 | ] |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * Execute migrations |
||
43 | */ |
||
44 | public function up() |
||
48 | |||
49 | /** |
||
50 | * Rollback migrations |
||
51 | */ |
||
52 | public function down() |
||
56 | |||
57 | /** |
||
58 | * @param string $link |
||
59 | * @param array $attributes |
||
60 | */ |
||
61 | private function updateOrInsertSettings(string $link, array $attributes) |
||
80 | } |
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
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key 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.