| Conditions | 1 |
| Paths | 1 |
| Total Lines | 30 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 17 | public function basicView() |
||
| 18 | { |
||
| 19 | |||
| 20 | $data['date_formats'] = array( |
||
|
|
|||
| 21 | 'Y-m-d' => '2010-12-23', |
||
| 22 | 'm-d-Y' => '12-23-2010', |
||
| 23 | 'd-m-Y' => '23-12-2010', |
||
| 24 | 'Y/m/d' => '2010/12/23', |
||
| 25 | 'm/d/Y' => '12/23/2010', |
||
| 26 | 'd/m/Y' => '23/12/2010', |
||
| 27 | 'Y.m.d' => '2010.12.23', |
||
| 28 | 'd.m.Y' => '23.12.2010', |
||
| 29 | 'm.d.Y' => '12.23.2010', |
||
| 30 | ); |
||
| 31 | |||
| 32 | $data['time_formats'] = array ( |
||
| 33 | 'H:i' => '23:00', |
||
| 34 | 'h:ia' => '11:00pm', |
||
| 35 | 'h:iA' => '11:00PM', |
||
| 36 | 'h:i a' => '11:00 pm', |
||
| 37 | 'h:i A' => '11:00 PM', |
||
| 38 | ); |
||
| 39 | |||
| 40 | $data['title'] = config('timecontrol.title'); |
||
| 41 | $data['email'] = config('timecontrol.email'); |
||
| 42 | $data['date'] = config('timecontrol.date'); |
||
| 43 | $data['time'] = config('timecontrol.time'); |
||
| 44 | |||
| 45 | return view('settings/basic', $data); |
||
| 46 | } |
||
| 47 | |||
| 61 |
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.