1 | <?php |
||
12 | class ProcessMonday extends Command |
||
13 | { |
||
14 | /** |
||
15 | * The name and signature of the console command. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $signature = 'emails:monday'; |
||
20 | |||
21 | /** |
||
22 | * The console command description. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $description = 'Process all commands for monday & send single email to Reporter'; |
||
27 | |||
28 | protected $classesToProcess = [ |
||
29 | 'notes' => SendReminders::class, |
||
30 | 'visits' => ExpiringVisits::class, |
||
31 | 'records' => RenewTraining::class, |
||
32 | 'destroyed' => DeleteUsers::class, |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * Execute the console command. |
||
37 | * |
||
38 | * @return mixed |
||
39 | */ |
||
40 | public function handle() |
||
51 | |||
52 | private function sendReporterEmail($array) |
||
58 | |||
59 | /** |
||
60 | * @return mixed |
||
61 | */ |
||
62 | private function getDutyList() |
||
73 | } |
||
74 |
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.