@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @param mixed $model |
66 | 66 | */ |
67 | - public function __construct($model = 'foo') |
|
67 | + public function __construct ($model = 'foo') |
|
68 | 68 | { |
69 | 69 | $this->model = $model; |
70 | 70 | } |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return \Illuminate\Http\JsonResponse |
76 | 76 | */ |
77 | - public function render() |
|
77 | + public function render () |
|
78 | 78 | { |
79 | 79 | return response()-> |
80 | 80 | /** @scrutinizer ignore-call */ |
81 | 81 | json([ |
82 | - 'messages' => trans('scheduler::exceptions.'. $this->trans, $this->parseValues()) |
|
82 | + 'messages' => trans('scheduler::exceptions.' . $this->trans, $this->parseValues()) |
|
83 | 83 | ], $this->statusCode); |
84 | 84 | } |
85 | 85 | |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return array |
90 | 90 | */ |
91 | - protected function parseValues() |
|
91 | + protected function parseValues () |
|
92 | 92 | { |
93 | - if(is_array($this->attributes) && is_array($this->values)) |
|
93 | + if (is_array($this->attributes) && is_array($this->values)) |
|
94 | 94 | return collect($this->attributes)->combine($this->values)->all(); |
95 | 95 | |
96 | 96 | return [ $this->attributes => $this->values ?? $this->isLower() ]; |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @return string |
103 | 103 | */ |
104 | - protected function isLower() |
|
104 | + protected function isLower () |
|
105 | 105 | { |
106 | 106 | return $this->lowercase ? strtolower($this->getAlias()) : $this->getAlias(); |
107 | 107 | } |
@@ -111,12 +111,12 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @return string |
113 | 113 | */ |
114 | - protected function getAlias() |
|
114 | + protected function getAlias () |
|
115 | 115 | { |
116 | - if(is_object($this->model)) |
|
116 | + if (is_object($this->model)) |
|
117 | 117 | $this->model = get_class($this->model); |
118 | 118 | |
119 | - return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso'; |
|
119 | + return collect(trans('scheduler::exceptions.aliases.' . $this->aliastype))->search($this->model) ?: 'Recurso'; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @param mixed $values |
126 | 126 | */ |
127 | - public function setValues($values) |
|
127 | + public function setValues ($values) |
|
128 | 128 | { |
129 | 129 | $this->values = $values; |
130 | 130 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return void |
30 | 30 | */ |
31 | - public function __construct($app) |
|
31 | + public function __construct ($app) |
|
32 | 32 | { |
33 | 33 | $this->app = $app; |
34 | 34 | } |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | * @param string|\Carbon\Carbon $end_at |
41 | 41 | * @return bool |
42 | 42 | */ |
43 | - public function hasScheduleBetween($model_type, $start_at, $end_at) |
|
43 | + public function hasScheduleBetween ($model_type, $start_at, $end_at) |
|
44 | 44 | { |
45 | - if(!Config::get('scheduler.enable_schedule_conflict')) |
|
45 | + if (!Config::get('scheduler.enable_schedule_conflict')) |
|
46 | 46 | return false; |
47 | 47 | |
48 | 48 | return !is_null( |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * que precisem ter uma certa duração. |
63 | 63 | * @return array |
64 | 64 | */ |
65 | - public function availableToday($model_type, $duration) |
|
65 | + public function availableToday ($model_type, $duration) |
|
66 | 66 | { |
67 | 67 | return $this->availableOn($model_type, Carbon::now(), $duration); |
68 | 68 | } |
@@ -76,38 +76,38 @@ discard block |
||
76 | 76 | * que precisem ter uma certa duração. |
77 | 77 | * @return array |
78 | 78 | */ |
79 | - public function availableOn($model_type, $today, $durationMinutes) |
|
79 | + public function availableOn ($model_type, $today, $durationMinutes) |
|
80 | 80 | { |
81 | 81 | $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
82 | 82 | $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); |
83 | 83 | |
84 | - $livres = []; |
|
84 | + $livres = [ ]; |
|
85 | 85 | $today = Carbon::parse($today->toDateString()); |
86 | - while($openingTime <= $closingTime) |
|
86 | + while ($openingTime <= $closingTime) |
|
87 | 87 | { |
88 | 88 | $add = true; |
89 | 89 | |
90 | 90 | foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
91 | - if($schedule->model_type != $model_type) |
|
91 | + if ($schedule->model_type != $model_type) |
|
92 | 92 | continue; |
93 | 93 | |
94 | 94 | $start = Carbon::parse($schedule->start_at); |
95 | 95 | $begin = Carbon::parse($start->toDateString()); |
96 | 96 | |
97 | - if($begin->greaterThan($today)) |
|
97 | + if ($begin->greaterThan($today)) |
|
98 | 98 | break; |
99 | 99 | |
100 | - if($begin->notEqualTo($today)) |
|
100 | + if ($begin->notEqualTo($today)) |
|
101 | 101 | continue; |
102 | 102 | |
103 | 103 | $end = Carbon::parse($schedule->end_at); |
104 | - if($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
104 | + if ($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
105 | 105 | && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
106 | 106 | $add = false; |
107 | 107 | } |
108 | 108 | |
109 | - if($add) |
|
110 | - $livres[] = [ |
|
109 | + if ($add) |
|
110 | + $livres[ ] = [ |
|
111 | 111 | 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
112 | 112 | 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
113 | 113 | ]; |
@@ -35,21 +35,21 @@ discard block |
||
35 | 35 | * @param string $relation |
36 | 36 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
37 | 37 | */ |
38 | - abstract public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null); |
|
38 | + abstract public function belongsTo ($related, $foreignKey = null, $ownerKey = null, $relation = null); |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Get the value of the model's primary key. |
42 | 42 | * |
43 | 43 | * @return mixed |
44 | 44 | */ |
45 | - abstract public function getKey(); |
|
45 | + abstract public function getKey (); |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait]. |
49 | 49 | * |
50 | 50 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
51 | 51 | */ |
52 | - public function schedules() |
|
52 | + public function schedules () |
|
53 | 53 | { |
54 | 54 | return $this->belongsTo(Config::get('scheduler.schedules_table'), 'model_id'); |
55 | 55 | } |
@@ -67,18 +67,18 @@ discard block |
||
67 | 67 | * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt |
68 | 68 | * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart |
69 | 69 | */ |
70 | - public function addSchedule($start_at, $end_at = null, $status = null) |
|
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)) |
|
72 | + if (!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
73 | 73 | throw new CantAddWithoutEnd; |
74 | 74 | |
75 | - $start_at = $this->parseToCarbon($start_at); |
|
75 | + $start_at = $this->parseToCarbon($start_at); |
|
76 | 76 | $end_at = $this->parseToCarbon($end_at, $start_at); |
77 | 77 | |
78 | - if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) |
|
78 | + if (Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) |
|
79 | 79 | throw new CantAddWithSameStartAt; |
80 | 80 | |
81 | - if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
81 | + if ($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
82 | 82 | throw new EndCantBeforeStart; |
83 | 83 | |
84 | 84 | $model_id = $this->getKey(); |
@@ -94,12 +94,12 @@ discard block |
||
94 | 94 | * @param \Carbon\Carbon $reference Data de referencia quando o [date] é inteiro. |
95 | 95 | * @return \Carbon\Carbon |
96 | 96 | */ |
97 | - public function parseToCarbon($date, $reference = null) |
|
97 | + public function parseToCarbon ($date, $reference = null) |
|
98 | 98 | { |
99 | - if(is_string($date)) |
|
99 | + if (is_string($date)) |
|
100 | 100 | return Carbon::parse($date); |
101 | 101 | |
102 | - if(is_int($date)) |
|
102 | + if (is_int($date)) |
|
103 | 103 | return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
104 | 104 | |
105 | 105 | return $date; |
@@ -111,12 +111,12 @@ discard block |
||
111 | 111 | * @param \Carbon\Carbon|string|int $value Valor que representará a data ou o id a ser buscado. |
112 | 112 | * @return H4ad\Scheduler\Models\Schedule|null |
113 | 113 | */ |
114 | - public function parseToSchedule($value) |
|
114 | + public function parseToSchedule ($value) |
|
115 | 115 | { |
116 | - if(is_int($value)) |
|
116 | + if (is_int($value)) |
|
117 | 117 | return Schedule::find($value); |
118 | 118 | |
119 | - if(is_string($value) || $value instanceof Carbon) |
|
119 | + if (is_string($value) || $value instanceof Carbon) |
|
120 | 120 | return Schedule::byStartAt($value)->first(); |
121 | 121 | |
122 | 122 | return null; |
@@ -134,17 +134,17 @@ discard block |
||
134 | 134 | * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
135 | 135 | * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
136 | 136 | */ |
137 | - public function removeSchedule($schedule) |
|
137 | + public function removeSchedule ($schedule) |
|
138 | 138 | { |
139 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
139 | + if (!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
140 | 140 | throw new CantRemoveByDate; |
141 | 141 | |
142 | 142 | $schedule = $this->parseToSchedule($schedule); |
143 | 143 | |
144 | - if(!($schedule instanceof Model)) |
|
144 | + if (!($schedule instanceof Model)) |
|
145 | 145 | throw (new ModelNotFound)->setValues(Schedule::class); |
146 | 146 | |
147 | - if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
147 | + if ($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
148 | 148 | throw new DoesNotBelong; |
149 | 149 | |
150 | 150 | return $schedule->delete(); |