| Conditions | 2 |
| Paths | 2 |
| Total Lines | 23 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | 2 | public function setOpeningHoursAttribute($data) |
|
| 30 | { |
||
| 31 | // clear previous open times |
||
| 32 | 2 | $this->dayOpenTimeRanges()->delete(); |
|
| 33 | |||
| 34 | 2 | if ($data == null) { |
|
| 35 | 1 | return; |
|
| 36 | } |
||
| 37 | |||
| 38 | $rangesArray = collect($data->flatMap(function (OpeningHoursForDay $openingHoursForDay, string $day) { |
||
| 39 | 1 | return $openingHoursForDay->map(function (TimeRange $timeRange) use ($day) { |
|
| 40 | return [ |
||
| 41 | 1 | 'day' => $day, |
|
| 42 | 1 | 'start' => $timeRange->start(), |
|
| 43 | 1 | 'end' => $timeRange->end() |
|
| 44 | ]; |
||
| 45 | 1 | }); |
|
| 46 | }))->map(function ($range) { |
||
| 47 | 1 | return new DayOpenTimeRange($range); |
|
| 48 | 1 | }); |
|
| 49 | |||
| 50 | 1 | $this->dayOpenTimeRanges()->saveMany($rangesArray); |
|
| 51 | } |
||
| 52 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: