@@ -42,8 +42,9 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function hasScheduleBetween($model_type, $start_at, $end_at) |
44 | 44 | { |
45 | - if(!Config::get('scheduler.enable_schedule_conflict')) |
|
46 | - return false; |
|
45 | + if(!Config::get('scheduler.enable_schedule_conflict')) { |
|
46 | + return false; |
|
47 | + } |
|
47 | 48 | |
48 | 49 | return !is_null( |
49 | 50 | Schedule::latest() |
@@ -88,29 +89,34 @@ discard block |
||
88 | 89 | $add = true; |
89 | 90 | |
90 | 91 | foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
91 | - if($schedule->model_type != $model_type) |
|
92 | - continue; |
|
92 | + if($schedule->model_type != $model_type) { |
|
93 | + continue; |
|
94 | + } |
|
93 | 95 | |
94 | 96 | $start = Carbon::parse($schedule->start_at); |
95 | 97 | $begin = Carbon::parse($start->toDateString()); |
96 | 98 | |
97 | - if($begin->greaterThan($today)) |
|
98 | - break; |
|
99 | + if($begin->greaterThan($today)) { |
|
100 | + break; |
|
101 | + } |
|
99 | 102 | |
100 | - if($begin->notEqualTo($today)) |
|
101 | - continue; |
|
103 | + if($begin->notEqualTo($today)) { |
|
104 | + continue; |
|
105 | + } |
|
102 | 106 | |
103 | 107 | $end = Carbon::parse($schedule->end_at); |
104 | 108 | if($start <= Carbon::parse($openingTime->toDateTimeString()) |
105 | - && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
|
106 | - $add = false; |
|
109 | + && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) { |
|
110 | + $add = false; |
|
111 | + } |
|
107 | 112 | } |
108 | 113 | |
109 | - if($add) |
|
110 | - $livres[] = [ |
|
114 | + if($add) { |
|
115 | + $livres[] = [ |
|
111 | 116 | 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
112 | 117 | 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
113 | 118 | ]; |
119 | + } |
|
114 | 120 | |
115 | 121 | $openingTime->addMinutes($durationMinutes); |
116 | 122 | } |
@@ -69,17 +69,20 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function addSchedule($start_at, $end_at = null, $status = null) |
71 | 71 | { |
72 | - if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
73 | - throw new CantAddWithoutEnd; |
|
72 | + if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) { |
|
73 | + throw new CantAddWithoutEnd; |
|
74 | + } |
|
74 | 75 | |
75 | 76 | $start_at = $this->parseToCarbon($start_at); |
76 | 77 | $end_at = $this->parseToCarbon($end_at, $start_at); |
77 | 78 | |
78 | - if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) |
|
79 | - throw new CantAddWithSameStartAt; |
|
79 | + if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) { |
|
80 | + throw new CantAddWithSameStartAt; |
|
81 | + } |
|
80 | 82 | |
81 | - if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
82 | - throw new EndCantBeforeStart; |
|
83 | + if($start_at->greaterThan($end_at) && !is_null($end_at)) { |
|
84 | + throw new EndCantBeforeStart; |
|
85 | + } |
|
83 | 86 | |
84 | 87 | $model_id = $this->getKey(); |
85 | 88 | $model_type = self::class; |
@@ -96,11 +99,13 @@ discard block |
||
96 | 99 | */ |
97 | 100 | public function parseToCarbon($date, $reference = null) |
98 | 101 | { |
99 | - if(is_string($date)) |
|
100 | - return Carbon::parse($date); |
|
102 | + if(is_string($date)) { |
|
103 | + return Carbon::parse($date); |
|
104 | + } |
|
101 | 105 | |
102 | - if(is_int($date)) |
|
103 | - return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
|
106 | + if(is_int($date)) { |
|
107 | + return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
|
108 | + } |
|
104 | 109 | |
105 | 110 | return $date; |
106 | 111 | } |
@@ -113,11 +118,13 @@ discard block |
||
113 | 118 | */ |
114 | 119 | public function parseToSchedule($value) |
115 | 120 | { |
116 | - if(is_int($value)) |
|
117 | - return Schedule::find($value); |
|
121 | + if(is_int($value)) { |
|
122 | + return Schedule::find($value); |
|
123 | + } |
|
118 | 124 | |
119 | - if(is_string($value) || $value instanceof Carbon) |
|
120 | - return Schedule::byStartAt($value)->first(); |
|
125 | + if(is_string($value) || $value instanceof Carbon) { |
|
126 | + return Schedule::byStartAt($value)->first(); |
|
127 | + } |
|
121 | 128 | |
122 | 129 | return null; |
123 | 130 | } |
@@ -136,16 +143,19 @@ discard block |
||
136 | 143 | */ |
137 | 144 | public function removeSchedule($schedule) |
138 | 145 | { |
139 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
140 | - throw new CantRemoveByDate; |
|
146 | + if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) { |
|
147 | + throw new CantRemoveByDate; |
|
148 | + } |
|
141 | 149 | |
142 | 150 | $schedule = $this->parseToSchedule($schedule); |
143 | 151 | |
144 | - if(!($schedule instanceof Model)) |
|
145 | - throw (new ModelNotFound)->setValues(Schedule::class); |
|
152 | + if(!($schedule instanceof Model)) { |
|
153 | + throw (new ModelNotFound)->setValues(Schedule::class); |
|
154 | + } |
|
146 | 155 | |
147 | - if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
148 | - throw new DoesNotBelong; |
|
156 | + if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) { |
|
157 | + throw new DoesNotBelong; |
|
158 | + } |
|
149 | 159 | |
150 | 160 | return $schedule->delete(); |
151 | 161 | } |