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 Webfactor\Laravel\OpeningHours\Traits; |
||
4 | |||
5 | use Carbon\Carbon; |
||
6 | use DateTimeInterface; |
||
7 | use Illuminate\Database\Eloquent\Builder; |
||
8 | use Webfactor\Laravel\OpeningHours\Entities\Day; |
||
9 | use Webfactor\Laravel\OpeningHours\Entities\Time; |
||
10 | use Webfactor\Laravel\OpeningHours\Exceptions\InvalidDayName; |
||
11 | use Webfactor\Laravel\OpeningHours\Exceptions\InvalidTimeString; |
||
12 | |||
13 | trait OpeningHoursScopes |
||
14 | { |
||
15 | protected $openingHoursRelationName = 'dayOpenTimeRanges'; |
||
16 | |||
17 | public function scopeWithOpeningHours(Builder $query) |
||
18 | { |
||
19 | return $query->with($this->openingHoursRelationName); |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * Get only open models. |
||
24 | * If no time and day are provided current time and day are used. |
||
25 | * If only time is provided current day is used. |
||
26 | * |
||
27 | * @param Builder $query |
||
28 | * @param Time|string|null $time defaults to current time |
||
29 | * @param string|null $day defaults to current day |
||
30 | * @return Builder|static |
||
0 ignored issues
–
show
|
|||
31 | * @throws InvalidDayName |
||
32 | * @throws InvalidTimeString |
||
33 | */ |
||
34 | 4 | public function scopeOpen(Builder $query, $time = null, string $day = null) |
|
35 | { |
||
36 | 4 | $now = Carbon::now(); |
|
37 | 4 | if ($time == null) { |
|
0 ignored issues
–
show
|
|||
38 | 1 | $time = Time::fromDateTime($now); |
|
39 | 3 | } elseif (is_string($time)) { |
|
40 | 2 | $time = Time::fromString($time); |
|
41 | } |
||
42 | |||
43 | 4 | if ($day == null) { |
|
0 ignored issues
–
show
|
|||
44 | 2 | $day = Day::onDateTime($now); |
|
45 | } else { |
||
46 | 2 | if (! Day::isValid($day)) { |
|
47 | throw new InvalidDayName(); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | 4 | return $query->whereHas($this->openingHoursRelationName, function (Builder $subquery) use ($day, $time) { |
|
52 | $subquery |
||
53 | 4 | ->where('day', $day) |
|
54 | 4 | ->where('start', '<=', $time) |
|
55 | 4 | ->where('end', '>=', $time); |
|
56 | 4 | }); |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Get only closed models. |
||
61 | * If no time and day are provided current time and day are used. |
||
62 | * If only time is provided current day is used. |
||
63 | * |
||
64 | * @param Builder $query |
||
65 | * @param Time|string|null $time defaults to current time |
||
66 | * @param string|null $day defaults to current day |
||
67 | * @return Builder|static |
||
0 ignored issues
–
show
|
|||
68 | * @throws InvalidDayName |
||
69 | * @throws InvalidTimeString |
||
70 | */ |
||
71 | 4 | public function scopeClosed(Builder $query, $time = null, string $day = null) |
|
72 | { |
||
73 | 4 | $now = Carbon::now(); |
|
74 | 4 | if ($time == null) { |
|
0 ignored issues
–
show
|
|||
75 | 1 | $time = Time::fromDateTime($now); |
|
76 | 3 | } elseif (is_string($time)) { |
|
77 | 2 | $time = Time::fromString($time); |
|
78 | } |
||
79 | |||
80 | 4 | if ($day == null) { |
|
0 ignored issues
–
show
|
|||
81 | 2 | $day = Day::onDateTime($now); |
|
82 | } else { |
||
83 | 2 | if (! Day::isValid($day)) { |
|
84 | throw new InvalidDayName(); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | 4 | return $query->whereDoesntHave($this->openingHoursRelationName, function (Builder $subquery) use ($day, $time) { |
|
89 | $subquery |
||
90 | 4 | ->where('day', $day) |
|
91 | 4 | ->where('start', '<=', $time) |
|
92 | 4 | ->where('end', '>=', $time); |
|
93 | 4 | }); |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Get all models open at the specified day at random time |
||
98 | * |
||
99 | * @param Builder $query |
||
100 | * @param string $day |
||
101 | * @return Builder|static |
||
0 ignored issues
–
show
|
|||
102 | * @throws InvalidDayName |
||
103 | */ |
||
104 | 1 | View Code Duplication | public function scopeOpenOn(Builder $query, string $day) |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
105 | { |
||
106 | 1 | if (! Day::isValid($day)) { |
|
107 | throw new InvalidDayName(); |
||
108 | } |
||
109 | |||
110 | 1 | return $query->whereHas($this->openingHoursRelationName, function (Builder $subquery) use ($day) { |
|
111 | 1 | $subquery->where('day', $day); |
|
112 | 1 | }); |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * Get all models closed at the specified day |
||
117 | * |
||
118 | * @param Builder $query |
||
119 | * @param string $day |
||
120 | * @return Builder|static |
||
0 ignored issues
–
show
|
|||
121 | * @throws InvalidDayName |
||
122 | */ |
||
123 | 1 | View Code Duplication | public function scopeClosedOn(Builder $query, string $day) |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
124 | { |
||
125 | 1 | if (! Day::isValid($day)) { |
|
126 | throw new InvalidDayName(); |
||
127 | } |
||
128 | |||
129 | 1 | return $query->whereDoesntHave($this->openingHoursRelationName, function (Builder $subquery) use ($day) { |
|
130 | 1 | $subquery->where('day', $day); |
|
131 | 1 | }); |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * Get all models open at the specified DateTime |
||
136 | * |
||
137 | * @param Builder $query |
||
138 | * @param DateTimeInterface $date |
||
139 | * @return mixed |
||
140 | */ |
||
141 | 1 | public function scopeOpenAt(Builder $query, DateTimeInterface $date) |
|
142 | { |
||
143 | 1 | return $query->open(Time::fromDateTime($date), Day::onDateTime($date)); |
|
144 | } |
||
145 | |||
146 | /** |
||
147 | * Get all models closed at the specified DateTime |
||
148 | * |
||
149 | * @param Builder $query |
||
150 | * @param DateTimeInterface $date |
||
151 | * @return mixed |
||
152 | */ |
||
153 | 1 | public function scopeClosedAt(Builder $query, DateTimeInterface $date) |
|
154 | { |
||
155 | 1 | return $query->closed(Time::fromDateTime($date), Day::onDateTime($date)); |
|
156 | } |
||
157 | } |
||
158 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.