@@ -33,8 +33,8 @@ |
||
33 | 33 | * |
34 | 34 | * @return string |
35 | 35 | */ |
36 | - protected static function getFacadeAccessor() |
|
36 | + protected static function getFacadeAccessor () |
|
37 | 37 | { |
38 | - return static::$app['scheduler']->newInstance(); |
|
38 | + return static::$app[ 'scheduler' ]->newInstance(); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | \ No newline at end of file |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | /** |
48 | 48 | * Construtor da classe. |
49 | 49 | */ |
50 | - public function __construct() |
|
50 | + public function __construct () |
|
51 | 51 | { |
52 | 52 | $this->query = Schedule::query(); |
53 | 53 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @param \Closure $boot_method |
60 | 60 | * @return void |
61 | 61 | */ |
62 | - public function init(Closure $boot) |
|
62 | + public function init (Closure $boot) |
|
63 | 63 | { |
64 | 64 | static::$boot = $boot; |
65 | 65 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param array $model_ids |
71 | 71 | * @return $this |
72 | 72 | */ |
73 | - public function avoid(array $model_ids) |
|
73 | + public function avoid (array $model_ids) |
|
74 | 74 | { |
75 | 75 | $this->query->whereNotIn('model_id', $model_ids); |
76 | 76 | |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | * @param \Carbon\Carbon|string $end_at |
85 | 85 | * @return boolean |
86 | 86 | */ |
87 | - public function hasConflict($start_at, $end_at) |
|
87 | + public function hasConflict ($start_at, $end_at) |
|
88 | 88 | { |
89 | - if(!Config::get('scheduler.enable_schedule_conflict')) |
|
89 | + if (!Config::get('scheduler.enable_schedule_conflict')) |
|
90 | 90 | return false; |
91 | 91 | |
92 | 92 | $this->byModel(); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @param \Carbon\Carbon|string $end_at |
103 | 103 | * @return $this |
104 | 104 | */ |
105 | - public function whereBetween($start_at, $end_at) |
|
105 | + public function whereBetween ($start_at, $end_at) |
|
106 | 106 | { |
107 | 107 | $this->query->where('start_at', '>=', $start_at) |
108 | 108 | ->where('end_at', '<=', $end_at); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * @param string|null $model_type |
117 | 117 | * @return $this |
118 | 118 | */ |
119 | - public function byModel() |
|
119 | + public function byModel () |
|
120 | 120 | { |
121 | 121 | $this->query->where('model_type', $this->getModelType()); |
122 | 122 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @param string $model_type |
130 | 130 | * @return $this |
131 | 131 | */ |
132 | - public function setModelType(string $model_type) |
|
132 | + public function setModelType (string $model_type) |
|
133 | 133 | { |
134 | 134 | $this->model_type = $model_type; |
135 | 135 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return string |
143 | 143 | */ |
144 | - public function getModelType() |
|
144 | + public function getModelType () |
|
145 | 145 | { |
146 | 146 | return $this->model_type ?? Config::get('scheduler.default_model'); |
147 | 147 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config. |
153 | 153 | * @return array |
154 | 154 | */ |
155 | - public function availableToday(int $duration, Carbon $openingTime = null) |
|
155 | + public function availableToday (int $duration, Carbon $openingTime = null) |
|
156 | 156 | { |
157 | 157 | return $this->availableOn(Carbon::today(), $duration, $openingTime); |
158 | 158 | } |
@@ -165,14 +165,14 @@ discard block |
||
165 | 165 | * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config. |
166 | 166 | * @return array |
167 | 167 | */ |
168 | - public function availableOn(Carbon $today, int $durationMinutes, Carbon $openingTime = null) |
|
168 | + public function availableOn (Carbon $today, int $durationMinutes, Carbon $openingTime = null) |
|
169 | 169 | { |
170 | 170 | $openingTime = $openingTime ?? Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
171 | 171 | $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); |
172 | 172 | |
173 | - $livres = []; |
|
173 | + $livres = [ ]; |
|
174 | 174 | $today = Carbon::parse($today->toDateString()); |
175 | - while($openingTime <= $closingTime) |
|
175 | + while ($openingTime <= $closingTime) |
|
176 | 176 | { |
177 | 177 | $add = true; |
178 | 178 | |
@@ -183,20 +183,20 @@ discard block |
||
183 | 183 | $start = Carbon::parse($schedule->start_at); |
184 | 184 | $begin = Carbon::parse($start->toDateString()); |
185 | 185 | |
186 | - if($begin->greaterThan($today)) |
|
186 | + if ($begin->greaterThan($today)) |
|
187 | 187 | break; |
188 | 188 | |
189 | - if($begin->notEqualTo($today)) |
|
189 | + if ($begin->notEqualTo($today)) |
|
190 | 190 | continue; |
191 | 191 | |
192 | 192 | $end = Carbon::parse($schedule->end_at); |
193 | 193 | |
194 | - if($this->isShouldntAdd($opening, $closing, $start, $end)) |
|
194 | + if ($this->isShouldntAdd($opening, $closing, $start, $end)) |
|
195 | 195 | $add = false; |
196 | 196 | } |
197 | 197 | |
198 | - if($add && $closing->lessThanOrEqualTo($closingTime)) |
|
199 | - $livres[] = [ |
|
198 | + if ($add && $closing->lessThanOrEqualTo($closingTime)) |
|
199 | + $livres[ ] = [ |
|
200 | 200 | 'start_at' => $opening, |
201 | 201 | 'end_at' => $closing |
202 | 202 | ]; |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @param \Carbon\Carbon $end |
217 | 217 | * @return boolean |
218 | 218 | */ |
219 | - private function isShouldntAdd(Carbon $opening, Carbon $closing, Carbon $start, Carbon $end) |
|
219 | + private function isShouldntAdd (Carbon $opening, Carbon $closing, Carbon $start, Carbon $end) |
|
220 | 220 | { |
221 | 221 | return $start <= $opening && $end >= $closing; |
222 | 222 | } |
@@ -233,24 +233,24 @@ discard block |
||
233 | 233 | * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart |
234 | 234 | * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt |
235 | 235 | */ |
236 | - public function validateSchedule($start_at, $end_at = null, int $status = null) |
|
236 | + public function validateSchedule ($start_at, $end_at = null, int $status = null) |
|
237 | 237 | { |
238 | - if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
238 | + if (!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
239 | 239 | throw new CantAddWithoutEnd; |
240 | 240 | |
241 | - $start_at = $this->parseToCarbon($start_at); |
|
241 | + $start_at = $this->parseToCarbon($start_at); |
|
242 | 242 | |
243 | - if(isset($end_at)) { |
|
243 | + if (isset($end_at)) { |
|
244 | 244 | $end_at = $this->parseToCarbon($end_at, $start_at); |
245 | 245 | |
246 | - if($start_at->greaterThan($end_at)) |
|
246 | + if ($start_at->greaterThan($end_at)) |
|
247 | 247 | throw new EndCantBeforeStart; |
248 | 248 | } |
249 | 249 | |
250 | - if(isset($status)) |
|
250 | + if (isset($status)) |
|
251 | 251 | ScheduleStatus::findOrFail($status); |
252 | 252 | |
253 | - if($this->hasConflict($start_at, $end_at ?? $start_at)) |
|
253 | + if ($this->hasConflict($start_at, $end_at ?? $start_at)) |
|
254 | 254 | throw new CantAddWithSameStartAt; |
255 | 255 | |
256 | 256 | $model_type = $this->getModelType(); |
@@ -267,15 +267,15 @@ discard block |
||
267 | 267 | * |
268 | 268 | * @throws \H4ad\Scheduler\Exceptions\IntInvalidArgument |
269 | 269 | */ |
270 | - public function parseToCarbon($date, $reference = null) |
|
270 | + public function parseToCarbon ($date, $reference = null) |
|
271 | 271 | { |
272 | - if($date instanceof Carbon) |
|
272 | + if ($date instanceof Carbon) |
|
273 | 273 | return $date; |
274 | 274 | |
275 | - if(is_string($date)) |
|
275 | + if (is_string($date)) |
|
276 | 276 | return Carbon::parse($date); |
277 | 277 | |
278 | - if(is_int($date) && !is_null($reference)) |
|
278 | + if (is_int($date) && !is_null($reference)) |
|
279 | 279 | return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
280 | 280 | |
281 | 281 | throw new IntInvalidArgument; |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | * @param \Carbon\Carbon|string|int $value Valor que representará a data ou o id a ser buscado. |
288 | 288 | * @return \H4ad\Scheduler\Models\Schedule|null |
289 | 289 | */ |
290 | - public function parseToSchedule($value) |
|
290 | + public function parseToSchedule ($value) |
|
291 | 291 | { |
292 | - if(is_int($value)) |
|
292 | + if (is_int($value)) |
|
293 | 293 | return Schedule::find($value); |
294 | 294 | |
295 | 295 | return Schedule::byStartAt($value)->first(); |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return $this |
302 | 302 | */ |
303 | - public function newInstance() |
|
303 | + public function newInstance () |
|
304 | 304 | { |
305 | 305 | return clone $this; |
306 | 306 | } |
@@ -310,11 +310,11 @@ discard block |
||
310 | 310 | * |
311 | 311 | * @return void |
312 | 312 | */ |
313 | - public function __clone() |
|
313 | + public function __clone () |
|
314 | 314 | { |
315 | 315 | $this->query = Schedule::query(); |
316 | 316 | |
317 | - if(isset(static::$boot)) |
|
317 | + if (isset(static::$boot)) |
|
318 | 318 | (static::$boot)($this); |
319 | 319 | } |
320 | 320 | } |
321 | 321 | \ No newline at end of file |
@@ -18,21 +18,21 @@ discard block |
||
18 | 18 | * @param string $localKey |
19 | 19 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
20 | 20 | */ |
21 | - abstract public function hasOne($related, $foreignKey = null, $localKey = null); |
|
21 | + abstract public function hasOne ($related, $foreignKey = null, $localKey = null); |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Get the value of the model's primary key. |
25 | 25 | * |
26 | 26 | * @return mixed |
27 | 27 | */ |
28 | - abstract public function getKey(); |
|
28 | + abstract public function getKey (); |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait]. |
32 | 32 | * |
33 | 33 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
34 | 34 | */ |
35 | - public function schedules(); |
|
35 | + public function schedules (); |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Agenda um horário para esta model. |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param array|null $data Informações opcionais que podem ser anexadas ao horário cadastrado. |
44 | 44 | * @return \H4ad\Scheduler\Models\Schedule |
45 | 45 | */ |
46 | - public function addSchedule($start_at, $end_at = null, int $status = null, array $data = null); |
|
46 | + public function addSchedule ($start_at, $end_at = null, int $status = null, array $data = null); |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado. |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
58 | 58 | * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
59 | 59 | */ |
60 | - public function removeSchedule($schedule); |
|
60 | + public function removeSchedule ($schedule); |
|
61 | 61 | |
62 | 62 | /** |
63 | 63 | * Retorna os horários disponiveis hoje para uma determinada model. |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config. |
67 | 67 | * @return array |
68 | 68 | */ |
69 | - public function availableToday(int $duration, Carbon $openingTime = null); |
|
69 | + public function availableToday (int $duration, Carbon $openingTime = null); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Retorna os horários disponiveis em um determinado dia para uma certa model. |
@@ -76,5 +76,5 @@ discard block |
||
76 | 76 | * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config. |
77 | 77 | * @return array |
78 | 78 | */ |
79 | - public function availableOn(Carbon $today, int $durationMinutes, Carbon $openingTime = null); |
|
79 | + public function availableOn (Carbon $today, int $durationMinutes, Carbon $openingTime = null); |
|
80 | 80 | } |
81 | 81 | \ No newline at end of file |
@@ -19,17 +19,17 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return void |
21 | 21 | */ |
22 | - public function boot() |
|
22 | + public function boot () |
|
23 | 23 | { |
24 | 24 | $this->publishes([ |
25 | - __DIR__.'/../config/config.php' => config_path('scheduler.php'), |
|
25 | + __DIR__ . '/../config/config.php' => config_path('scheduler.php'), |
|
26 | 26 | ]); |
27 | 27 | |
28 | - $this->loadMigrationsFrom(__DIR__.'/Migrations'); |
|
29 | - $this->loadTranslationsFrom(__DIR__.'/Translations', 'scheduler'); |
|
28 | + $this->loadMigrationsFrom(__DIR__ . '/Migrations'); |
|
29 | + $this->loadTranslationsFrom(__DIR__ . '/Translations', 'scheduler'); |
|
30 | 30 | |
31 | 31 | $this->publishes([ |
32 | - __DIR__.'/Translations' => resource_path('lang/vendor/scheduler'), |
|
32 | + __DIR__ . '/Translations' => resource_path('lang/vendor/scheduler'), |
|
33 | 33 | ]); |
34 | 34 | } |
35 | 35 | |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return void |
40 | 40 | */ |
41 | - public function register() |
|
41 | + public function register () |
|
42 | 42 | { |
43 | 43 | $this->app->alias(Scheduler::class, 'scheduler'); |
44 | 44 | |
45 | - $this->app->singleton('scheduler', function ($app) { |
|
45 | + $this->app->singleton('scheduler', function($app) { |
|
46 | 46 | return new Scheduler; |
47 | 47 | }); |
48 | 48 | |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return void |
56 | 56 | */ |
57 | - private function mergeConfig() |
|
57 | + private function mergeConfig () |
|
58 | 58 | { |
59 | 59 | $this->mergeConfigFrom( |
60 | - __DIR__.'/../config/config.php', 'scheduler' |
|
60 | + __DIR__ . '/../config/config.php', 'scheduler' |
|
61 | 61 | ); |
62 | 62 | } |
63 | 63 | } |
64 | 64 | \ No newline at end of file |
@@ -31,21 +31,21 @@ discard block |
||
31 | 31 | * @param string $localKey |
32 | 32 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
33 | 33 | */ |
34 | - abstract public function hasOne($related, $foreignKey = null, $localKey = null); |
|
34 | + abstract public function hasOne ($related, $foreignKey = null, $localKey = null); |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Get the value of the model's primary key. |
38 | 38 | * |
39 | 39 | * @return mixed |
40 | 40 | */ |
41 | - abstract public function getKey(); |
|
41 | + abstract public function getKey (); |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Retorna apenas o horário que possui o mesmo [model_id] do [parent] dessa [trait]. |
45 | 45 | * |
46 | 46 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
47 | 47 | */ |
48 | - public function schedules() |
|
48 | + public function schedules () |
|
49 | 49 | { |
50 | 50 | return $this->hasOne(Config::get('scheduler.schedules_table'), 'model_id'); |
51 | 51 | } |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | * @param array|null $data Informações opcionais que podem ser anexadas ao horário cadastrado. |
60 | 60 | * @return \H4ad\Scheduler\Models\Schedule |
61 | 61 | */ |
62 | - public function addSchedule($start_at, $end_at = null, int $status = null, array $data = null) |
|
62 | + public function addSchedule ($start_at, $end_at = null, int $status = null, array $data = null) |
|
63 | 63 | { |
64 | 64 | $schedule = Scheduler::setModelType(self::class)->byModel()->validateSchedule($start_at, $end_at, $status); |
65 | 65 | |
66 | - $schedule['model_id'] = $this->getKey(); |
|
67 | - $schedule['data'] = $data; |
|
66 | + $schedule[ 'model_id' ] = $this->getKey(); |
|
67 | + $schedule[ 'data' ] = $data; |
|
68 | 68 | |
69 | 69 | return Schedule::create($schedule); |
70 | 70 | } |
@@ -81,17 +81,17 @@ discard block |
||
81 | 81 | * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
82 | 82 | * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
83 | 83 | */ |
84 | - public function removeSchedule($schedule) |
|
84 | + public function removeSchedule ($schedule) |
|
85 | 85 | { |
86 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
86 | + if (!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
87 | 87 | throw new CantRemoveByDate; |
88 | 88 | |
89 | 89 | $schedule = Scheduler::parseToSchedule($schedule); |
90 | 90 | |
91 | - if(!($schedule instanceof Model)) |
|
91 | + if (!($schedule instanceof Model)) |
|
92 | 92 | throw (new ModelNotFound)->setValues(Schedule::class); |
93 | 93 | |
94 | - if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
94 | + if ($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
95 | 95 | throw new DoesNotBelong; |
96 | 96 | |
97 | 97 | return $schedule->delete(); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config. |
105 | 105 | * @return array |
106 | 106 | */ |
107 | - public function availableToday(int $duration, Carbon $openingTime = null) |
|
107 | + public function availableToday (int $duration, Carbon $openingTime = null) |
|
108 | 108 | { |
109 | 109 | return Scheduler::byModel(self::class)->availableToday($duration, $openingTime); |
110 | 110 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @param \Carbon\Carbon|null $openingTime Serve como referencia para buscar horários livres. Se for nulo, ele busca a referencia da config. |
118 | 118 | * @return array |
119 | 119 | */ |
120 | - public function availableOn(Carbon $today, int $durationMinutes, Carbon $openingTime = null) |
|
120 | + public function availableOn (Carbon $today, int $durationMinutes, Carbon $openingTime = null) |
|
121 | 121 | { |
122 | 122 | return Scheduler::byModel(self::class)->availableOn($today, $durationMinutes, $openingTime); |
123 | 123 | } |