This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Timegridio\Concierge\Models; |
||
4 | |||
5 | use Carbon\Carbon; |
||
6 | use Illuminate\Database\Eloquent\Model as EloquentModel; |
||
7 | |||
8 | /** |
||
9 | * @property int $id |
||
10 | * @property int $business_id |
||
11 | * @property Illuminate\Support\Collection $business |
||
12 | * @property int $service_id |
||
13 | * @property Timegridio\Concierge\Models\Service $service |
||
14 | * @property int $humanresource_id |
||
15 | * @property Timegridio\Concierge\Models\Humanresource $humanresource |
||
16 | * @property string $date |
||
17 | * @property \Carbon\Carbon $start_at |
||
18 | * @property \Carbon\Carbon $finish_at |
||
19 | * @property int $capacity |
||
20 | */ |
||
21 | class Vacancy extends EloquentModel |
||
22 | { |
||
23 | /** |
||
24 | * The attributes that are mass assignable. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $fillable = [ |
||
29 | 'business_id', |
||
30 | 'service_id', |
||
31 | 'humanresource_id', |
||
32 | 'date', |
||
33 | 'start_at', |
||
34 | 'finish_at', |
||
35 | 'capacity', |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * The attributes that aren't mass assignable. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $guarded = ['id']; |
||
44 | |||
45 | /** |
||
46 | * The attributes that should be mutated to dates. |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $dates = ['start_at', 'finish_at']; |
||
51 | |||
52 | /////////////////// |
||
53 | // Relationships // |
||
54 | /////////////////// |
||
55 | |||
56 | /** |
||
57 | * belongs to Business. |
||
58 | * |
||
59 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo Relationship Vacancy belongs to Business query |
||
60 | */ |
||
61 | 14 | public function business() |
|
62 | { |
||
63 | 14 | return $this->belongsTo(Business::class); |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * for Service. |
||
68 | * |
||
69 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo Relationship Vacancy is for providing Service query |
||
70 | */ |
||
71 | 24 | public function service() |
|
72 | { |
||
73 | 24 | return $this->belongsTo(Service::class); |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * Humanresource. |
||
78 | * |
||
79 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
80 | */ |
||
81 | 16 | public function humanresource() |
|
82 | { |
||
83 | 16 | return $this->belongsTo(Humanresource::class); |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * holds many Appointments. |
||
88 | * |
||
89 | * @return \Illuminate\Database\Eloquent\Relations\HasMany Relationship Vacancy belongs to Business query |
||
90 | */ |
||
91 | 10 | public function appointments() |
|
92 | { |
||
93 | 10 | return $this->hasMany(Appointment::class); |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Humanresource Slug. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function humanresourceSlug() |
||
102 | { |
||
103 | if ($this->humanresource_id) { |
||
104 | return $this->humanresource->slug; |
||
105 | } |
||
106 | |||
107 | return ''; |
||
108 | } |
||
109 | |||
110 | //////////// |
||
111 | // Scopes // |
||
112 | //////////// |
||
113 | |||
114 | /** |
||
115 | * Scope For Date. |
||
116 | * |
||
117 | * @param Illuminate\Database\Query $query |
||
118 | * @param Carbon $date Date of inquiry |
||
119 | * |
||
120 | * @return Illuminate\Database\Query Scoped query |
||
121 | */ |
||
122 | 6 | public function scopeForDate($query, Carbon $date) |
|
123 | { |
||
124 | 6 | return $query->where('date', '=', $date->toDateString()); |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * Scope For DateTime. |
||
129 | * |
||
130 | * @param Illuminate\Database\Query $query |
||
131 | * @param Carbon $datetime Date and Time of inquiry |
||
132 | * |
||
133 | * @return Illuminate\Database\Query Scoped query |
||
134 | */ |
||
135 | 6 | public function scopeForDateTime($query, Carbon $datetime) |
|
136 | { |
||
137 | 6 | return $query->where('start_at', '<=', $datetime->toDateTimeString()) |
|
138 | 6 | ->where('finish_at', '>=', $datetime->toDateTimeString()); |
|
139 | } |
||
140 | |||
141 | /** |
||
142 | * Scope only Future. |
||
143 | * |
||
144 | * @param Illuminate\Database\Query $query |
||
145 | * @param \Carbon\Carbon $since |
||
146 | * |
||
147 | * @return Illuminate\Database\Query Scoped query |
||
148 | */ |
||
149 | 3 | public function scopeFuture($query, $since = null) |
|
150 | { |
||
151 | 3 | if (!$since) { |
|
152 | 1 | $since = Carbon::now(); |
|
153 | } |
||
154 | |||
155 | 3 | return $query->where('date', '>=', $since->toDateTimeString()); |
|
156 | } |
||
157 | |||
158 | /** |
||
159 | * Scope Until. |
||
160 | * |
||
161 | * @param Illuminate\Database\Query $query |
||
162 | * @param \Carbon\Carbon $until |
||
163 | * |
||
164 | * @return Illuminate\Database\Query Scoped query |
||
165 | */ |
||
166 | 2 | public function scopeUntil($query, $until = null) |
|
167 | { |
||
168 | 2 | if (!$until) { |
|
169 | return $query; |
||
170 | } |
||
171 | |||
172 | 2 | return $query->where('date', '<', $until->toDateTimeString()); |
|
173 | } |
||
174 | |||
175 | /** |
||
176 | * Scope For Service. |
||
177 | * |
||
178 | * @param Illuminate\Database\Query $query |
||
179 | * @param int serviceId $service Inquired Service to filter |
||
180 | * |
||
181 | * @return Illuminate\Database\Query Scoped query |
||
182 | */ |
||
183 | 14 | public function scopeForService($query, $serviceId) |
|
184 | { |
||
185 | 14 | return $query->where('service_id', '=', $serviceId); |
|
186 | } |
||
187 | |||
188 | ///////////////////// |
||
189 | // Soft Attributes // |
||
190 | ///////////////////// |
||
191 | |||
192 | /** |
||
193 | * is Holding Any Appointment for given User. |
||
194 | * |
||
195 | * ToDo: Remove from here as needs knowledge from User |
||
196 | * |
||
197 | * @param int $userId User to check belonging Appointments |
||
198 | * |
||
199 | * @return bool Vacancy holds at least one Appointment of User |
||
200 | */ |
||
201 | 2 | public function isHoldingAnyFor($userId) |
|
202 | { |
||
203 | 2 | $appointments = $this->appointments()->get(); |
|
204 | |||
205 | 2 | foreach ($appointments as $appointment) { |
|
206 | 2 | $contact = $appointment->contact()->first(); |
|
207 | 2 | if ($contact->isProfileOf($userId)) { |
|
208 | 2 | return true; |
|
209 | } |
||
210 | } |
||
211 | |||
212 | 1 | return false; |
|
213 | } |
||
214 | |||
215 | /** |
||
216 | * is Full. |
||
217 | * |
||
218 | * @return bool Vacancy is fully booked |
||
219 | */ |
||
220 | # public function isFull() |
||
0 ignored issues
–
show
|
|||
221 | # { |
||
222 | # return $this->getFreeSlotsCount() <= 0; |
||
223 | # } |
||
224 | |||
225 | /** |
||
226 | * get free slots count. |
||
227 | * |
||
228 | * @return int Count Capacity minus Used |
||
229 | */ |
||
230 | # public function getFreeSlotsCount() |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
49% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
231 | # { |
||
232 | # $count = $this->appointments()->active()->count(); |
||
233 | # |
||
234 | # return $this->capacity - $count; |
||
235 | # } |
||
236 | |||
237 | /** |
||
238 | * get capacity. |
||
239 | * |
||
240 | * @return int Capacity of the vacancy (in appointment instances) |
||
241 | */ |
||
242 | 15 | public function getCapacityAttribute() |
|
243 | { |
||
244 | 15 | if ($this->humanresource) { |
|
245 | return intval($this->humanresource->capacity); |
||
246 | } |
||
247 | |||
248 | 15 | return intval($this->attributes['capacity']); |
|
249 | } |
||
250 | |||
251 | /** |
||
252 | * has Room. |
||
253 | * |
||
254 | * @return bool There is more capacity than used |
||
255 | */ |
||
256 | 4 | public function hasRoom() |
|
257 | { |
||
258 | 4 | return $this->capacity > $this->appointments()->active()->count(); |
|
259 | } |
||
260 | |||
261 | /** |
||
262 | * has Room between time. |
||
263 | * |
||
264 | * @return bool There is more capacity than used |
||
265 | */ |
||
266 | 4 | public function hasRoomBetween(Carbon $startAt, Carbon $finishAt) |
|
267 | { |
||
268 | 4 | return $this->capacity > $this->business |
|
269 | 4 | ->bookings() |
|
270 | 4 | ->active() |
|
271 | 4 | ->affectingInterval($startAt, $finishAt) |
|
272 | 4 | ->affectingHumanresource($this->humanresource_id) |
|
273 | 4 | ->count() && |
|
274 | 4 | ($this->start_at <= $startAt && $this->finish_at >= $finishAt); |
|
275 | } |
||
276 | |||
277 | /** |
||
278 | * Get available capacity between time. |
||
279 | * |
||
280 | * @return int Available capacity |
||
281 | */ |
||
282 | 6 | public function getAvailableCapacityBetween(Carbon $startAt, Carbon $finishAt) |
|
283 | { |
||
284 | 6 | if (!($this->start_at <= $startAt && $this->finish_at >= $finishAt)) { |
|
285 | 5 | return 0; |
|
286 | } |
||
287 | |||
288 | 6 | $count = $this->business |
|
289 | 6 | ->bookings() |
|
290 | 6 | ->active() |
|
291 | 6 | ->affectingHumanresource($this->humanresource_id) |
|
292 | 6 | ->affectingInterval($startAt, $finishAt) |
|
293 | 6 | ->count(); |
|
294 | |||
295 | 6 | return $this->capacity - intval($count); |
|
296 | } |
||
297 | } |
||
298 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.