@@ -70,20 +70,23 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function addSchedule($start_at, $end_at = null, $status = null) |
72 | 72 | { |
73 | - if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
74 | - throw new CantAddWithoutEnd; |
|
73 | + if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) { |
|
74 | + throw new CantAddWithoutEnd; |
|
75 | + } |
|
75 | 76 | |
76 | 77 | $start_at = $this->parseToCarbon($start_at); |
77 | 78 | |
78 | 79 | if(!is_null($end_at)) { |
79 | 80 | $end_at = $this->parseToCarbon($end_at, $start_at); |
80 | 81 | |
81 | - if($start_at->greaterThan($end_at)) |
|
82 | - throw new EndCantBeforeStart; |
|
82 | + if($start_at->greaterThan($end_at)) { |
|
83 | + throw new EndCantBeforeStart; |
|
84 | + } |
|
83 | 85 | } |
84 | 86 | |
85 | - if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) |
|
86 | - throw new CantAddWithSameStartAt; |
|
87 | + if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) { |
|
88 | + throw new CantAddWithSameStartAt; |
|
89 | + } |
|
87 | 90 | |
88 | 91 | $model_id = $this->getKey(); |
89 | 92 | $model_type = self::class; |
@@ -131,14 +134,17 @@ discard block |
||
131 | 134 | */ |
132 | 135 | public function parseToCarbon($date, $reference = null) |
133 | 136 | { |
134 | - if($date instanceof Carbon) |
|
135 | - return $date; |
|
137 | + if($date instanceof Carbon) { |
|
138 | + return $date; |
|
139 | + } |
|
136 | 140 | |
137 | - if(is_string($date)) |
|
138 | - return Carbon::parse($date); |
|
141 | + if(is_string($date)) { |
|
142 | + return Carbon::parse($date); |
|
143 | + } |
|
139 | 144 | |
140 | - if(is_int($date) && !is_null($reference)) |
|
141 | - return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
|
145 | + if(is_int($date) && !is_null($reference)) { |
|
146 | + return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
|
147 | + } |
|
142 | 148 | |
143 | 149 | throw new IntInvalidArgument; |
144 | 150 | } |
@@ -151,8 +157,9 @@ discard block |
||
151 | 157 | */ |
152 | 158 | public function parseToSchedule($value) |
153 | 159 | { |
154 | - if(is_int($value)) |
|
155 | - return Schedule::find($value); |
|
160 | + if(is_int($value)) { |
|
161 | + return Schedule::find($value); |
|
162 | + } |
|
156 | 163 | |
157 | 164 | return Schedule::byStartAt($value)->first(); |
158 | 165 | } |
@@ -171,16 +178,19 @@ discard block |
||
171 | 178 | */ |
172 | 179 | public function removeSchedule($schedule) |
173 | 180 | { |
174 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
175 | - throw new CantRemoveByDate; |
|
181 | + if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) { |
|
182 | + throw new CantRemoveByDate; |
|
183 | + } |
|
176 | 184 | |
177 | 185 | $schedule = $this->parseToSchedule($schedule); |
178 | 186 | |
179 | - if(!($schedule instanceof Model)) |
|
180 | - throw (new ModelNotFound)->setValues(Schedule::class); |
|
187 | + if(!($schedule instanceof Model)) { |
|
188 | + throw (new ModelNotFound)->setValues(Schedule::class); |
|
189 | + } |
|
181 | 190 | |
182 | - if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
183 | - throw new DoesNotBelong; |
|
191 | + if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) { |
|
192 | + throw new DoesNotBelong; |
|
193 | + } |
|
184 | 194 | |
185 | 195 | return $schedule->delete(); |
186 | 196 | } |
@@ -43,8 +43,9 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function hasScheduleBetween($model_type, $start_at, $end_at) |
45 | 45 | { |
46 | - if(!Config::get('scheduler.enable_schedule_conflict')) |
|
47 | - return false; |
|
46 | + if(!Config::get('scheduler.enable_schedule_conflict')) { |
|
47 | + return false; |
|
48 | + } |
|
48 | 49 | |
49 | 50 | return !is_null( |
50 | 51 | Schedule::latest() |
@@ -84,8 +85,9 @@ discard block |
||
84 | 85 | public function availableOn($model_type, $today, $durationMinutes, $openingTime = null) |
85 | 86 | { |
86 | 87 | //TODO: Melhorar a performance desse método. |
87 | - if(is_null($openingTime)) |
|
88 | - $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
|
88 | + if(is_null($openingTime)) { |
|
89 | + $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
|
90 | + } |
|
89 | 91 | |
90 | 92 | $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); |
91 | 93 | |
@@ -96,30 +98,35 @@ discard block |
||
96 | 98 | $add = true; |
97 | 99 | |
98 | 100 | foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
99 | - if($schedule->model_type != $model_type) |
|
100 | - continue; |
|
101 | + if($schedule->model_type != $model_type) { |
|
102 | + continue; |
|
103 | + } |
|
101 | 104 | |
102 | 105 | $start = Carbon::parse($schedule->start_at); |
103 | 106 | $begin = Carbon::parse($start->toDateString()); |
104 | 107 | |
105 | - if($begin->greaterThan($today)) |
|
106 | - break; |
|
108 | + if($begin->greaterThan($today)) { |
|
109 | + break; |
|
110 | + } |
|
107 | 111 | |
108 | - if($begin->notEqualTo($today)) |
|
109 | - continue; |
|
112 | + if($begin->notEqualTo($today)) { |
|
113 | + continue; |
|
114 | + } |
|
110 | 115 | |
111 | 116 | $end = Carbon::parse($schedule->end_at); |
112 | 117 | if($start <= Carbon::parse($openingTime->toDateTimeString()) |
113 | - && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
|
114 | - $add = false; |
|
118 | + && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) { |
|
119 | + $add = false; |
|
120 | + } |
|
115 | 121 | } |
116 | 122 | |
117 | 123 | $endTime = Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes); |
118 | - if($add && $endTime->lessThanOrEqualTo($closingTime)) |
|
119 | - $livres[] = [ |
|
124 | + if($add && $endTime->lessThanOrEqualTo($closingTime)) { |
|
125 | + $livres[] = [ |
|
120 | 126 | 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
121 | 127 | 'end_at' => $endTime |
122 | 128 | ]; |
129 | + } |
|
123 | 130 | |
124 | 131 | $openingTime->addMinutes($durationMinutes); |
125 | 132 | } |