@@ -88,8 +88,9 @@ discard block |
||
88 | 88 | */ |
89 | 89 | protected function parseValues() |
90 | 90 | { |
91 | - if(is_array($this->attributes) && is_array($this->values)) |
|
92 | - return collect($this->attributes)->combine($this->values)->all(); |
|
91 | + if(is_array($this->attributes) && is_array($this->values)) { |
|
92 | + return collect($this->attributes)->combine($this->values)->all(); |
|
93 | + } |
|
93 | 94 | |
94 | 95 | return [ $this->attributes => $this->values ?? $this->isLower() ]; |
95 | 96 | } |
@@ -111,8 +112,9 @@ discard block |
||
111 | 112 | */ |
112 | 113 | protected function getAlias() |
113 | 114 | { |
114 | - if(is_object($this->model)) |
|
115 | - $this->model = get_class($this->model); |
|
115 | + if(is_object($this->model)) { |
|
116 | + $this->model = get_class($this->model); |
|
117 | + } |
|
116 | 118 | |
117 | 119 | return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso'; |
118 | 120 | } |
@@ -59,14 +59,17 @@ |
||
59 | 59 | */ |
60 | 60 | public function parseStatusKey($status) |
61 | 61 | { |
62 | - if(is_int($status)) |
|
63 | - $status = ScheduleStatus::find($status); |
|
62 | + if(is_int($status)) { |
|
63 | + $status = ScheduleStatus::find($status); |
|
64 | + } |
|
64 | 65 | |
65 | - if(is_string($status)) |
|
66 | - $status = ScheduleStatus::where('name', $status)->first(); |
|
66 | + if(is_string($status)) { |
|
67 | + $status = ScheduleStatus::where('name', $status)->first(); |
|
68 | + } |
|
67 | 69 | |
68 | - if(is_null($status)) |
|
69 | - throw (new ModelNotFound)->setValues(ScheduleStatus::class); |
|
70 | + if(is_null($status)) { |
|
71 | + throw (new ModelNotFound)->setValues(ScheduleStatus::class); |
|
72 | + } |
|
70 | 73 | |
71 | 74 | return ['status' => $status->id]; |
72 | 75 | } |
@@ -110,16 +110,19 @@ |
||
110 | 110 | */ |
111 | 111 | public function removeSchedule($schedule) |
112 | 112 | { |
113 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
114 | - throw new CantRemoveByDate; |
|
113 | + if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) { |
|
114 | + throw new CantRemoveByDate; |
|
115 | + } |
|
115 | 116 | |
116 | 117 | $schedule = Scheduler::parseToSchedule($schedule); |
117 | 118 | |
118 | - if(!($schedule instanceof Model)) |
|
119 | - throw (new ModelNotFound)->setValues(Schedule::class); |
|
119 | + if(!($schedule instanceof Model)) { |
|
120 | + throw (new ModelNotFound)->setValues(Schedule::class); |
|
121 | + } |
|
120 | 122 | |
121 | - if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
122 | - throw new DoesNotBelong; |
|
123 | + if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) { |
|
124 | + throw new DoesNotBelong; |
|
125 | + } |
|
123 | 126 | |
124 | 127 | return $schedule->delete(); |
125 | 128 | } |
@@ -86,8 +86,9 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function hasConflict($start_at, $end_at) |
88 | 88 | { |
89 | - if(!Config::get('scheduler.enable_schedule_conflict')) |
|
90 | - return false; |
|
89 | + if(!Config::get('scheduler.enable_schedule_conflict')) { |
|
90 | + return false; |
|
91 | + } |
|
91 | 92 | |
92 | 93 | $this->byModel(); |
93 | 94 | $this->whereBetween($start_at, $end_at); |
@@ -183,23 +184,27 @@ discard block |
||
183 | 184 | $start = Carbon::parse($schedule->start_at); |
184 | 185 | $begin = Carbon::parse($start->toDateString()); |
185 | 186 | |
186 | - if($begin->greaterThan($today)) |
|
187 | - break; |
|
187 | + if($begin->greaterThan($today)) { |
|
188 | + break; |
|
189 | + } |
|
188 | 190 | |
189 | - if($begin->notEqualTo($today)) |
|
190 | - continue; |
|
191 | + if($begin->notEqualTo($today)) { |
|
192 | + continue; |
|
193 | + } |
|
191 | 194 | |
192 | 195 | $end = Carbon::parse($schedule->end_at); |
193 | 196 | |
194 | - if($this->isShouldntAdd($opening, $closing, $start, $end)) |
|
195 | - $add = false; |
|
197 | + if($this->isShouldntAdd($opening, $closing, $start, $end)) { |
|
198 | + $add = false; |
|
199 | + } |
|
196 | 200 | } |
197 | 201 | |
198 | - if($add && $closing->lessThanOrEqualTo($closingTime)) |
|
199 | - $livres[] = [ |
|
202 | + if($add && $closing->lessThanOrEqualTo($closingTime)) { |
|
203 | + $livres[] = [ |
|
200 | 204 | 'start_at' => $opening, |
201 | 205 | 'end_at' => $closing |
202 | 206 | ]; |
207 | + } |
|
203 | 208 | |
204 | 209 | $openingTime->addMinutes($durationMinutes); |
205 | 210 | } |
@@ -235,23 +240,27 @@ discard block |
||
235 | 240 | */ |
236 | 241 | public function validateSchedule($start_at, $end_at = null, int $status = null) |
237 | 242 | { |
238 | - if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
239 | - throw new CantAddWithoutEnd; |
|
243 | + if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) { |
|
244 | + throw new CantAddWithoutEnd; |
|
245 | + } |
|
240 | 246 | |
241 | 247 | $start_at = $this->parseToCarbon($start_at); |
242 | 248 | |
243 | 249 | if(isset($end_at)) { |
244 | 250 | $end_at = $this->parseToCarbon($end_at, $start_at); |
245 | 251 | |
246 | - if($start_at->greaterThan($end_at)) |
|
247 | - throw new EndCantBeforeStart; |
|
252 | + if($start_at->greaterThan($end_at)) { |
|
253 | + throw new EndCantBeforeStart; |
|
254 | + } |
|
248 | 255 | } |
249 | 256 | |
250 | - if(isset($status)) |
|
251 | - ScheduleStatus::findOrFail($status); |
|
257 | + if(isset($status)) { |
|
258 | + ScheduleStatus::findOrFail($status); |
|
259 | + } |
|
252 | 260 | |
253 | - if($this->hasConflict($start_at, $end_at ?? $start_at)) |
|
254 | - throw new CantAddWithSameStartAt; |
|
261 | + if($this->hasConflict($start_at, $end_at ?? $start_at)) { |
|
262 | + throw new CantAddWithSameStartAt; |
|
263 | + } |
|
255 | 264 | |
256 | 265 | $model_type = $this->getModelType(); |
257 | 266 | |
@@ -269,14 +278,17 @@ discard block |
||
269 | 278 | */ |
270 | 279 | public function parseToCarbon($date, $reference = null) |
271 | 280 | { |
272 | - if($date instanceof Carbon) |
|
273 | - return $date; |
|
281 | + if($date instanceof Carbon) { |
|
282 | + return $date; |
|
283 | + } |
|
274 | 284 | |
275 | - if(is_string($date)) |
|
276 | - return Carbon::parse($date); |
|
285 | + if(is_string($date)) { |
|
286 | + return Carbon::parse($date); |
|
287 | + } |
|
277 | 288 | |
278 | - if(is_int($date) && !is_null($reference)) |
|
279 | - return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
|
289 | + if(is_int($date) && !is_null($reference)) { |
|
290 | + return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
|
291 | + } |
|
280 | 292 | |
281 | 293 | throw new IntInvalidArgument; |
282 | 294 | } |
@@ -289,8 +301,9 @@ discard block |
||
289 | 301 | */ |
290 | 302 | public function parseToSchedule($value) |
291 | 303 | { |
292 | - if(is_int($value)) |
|
293 | - return Schedule::find($value); |
|
304 | + if(is_int($value)) { |
|
305 | + return Schedule::find($value); |
|
306 | + } |
|
294 | 307 | |
295 | 308 | return Schedule::byStartAt($value)->first(); |
296 | 309 | } |
@@ -314,7 +327,8 @@ discard block |
||
314 | 327 | { |
315 | 328 | $this->query = Schedule::query(); |
316 | 329 | |
317 | - if(isset(static::$boot)) |
|
318 | - (static::$boot)($this); |
|
330 | + if(isset(static::$boot)) { |
|
331 | + (static::$boot)($this); |
|
332 | + } |
|
319 | 333 | } |
320 | 334 | } |
321 | 335 | \ No newline at end of file |