1 | <?php namespace Arcanedev\LaravelImpersonator; |
||
14 | class Impersonator implements Contracts\Impersonator |
||
15 | { |
||
16 | /* ----------------------------------------------------------------- |
||
17 | | Properties |
||
18 | | ----------------------------------------------------------------- |
||
19 | */ |
||
20 | |||
21 | /** @var \Illuminate\Contracts\Foundation\Application */ |
||
22 | protected $app; |
||
23 | |||
24 | /* ----------------------------------------------------------------- |
||
25 | | Constructor |
||
26 | | ----------------------------------------------------------------- |
||
27 | */ |
||
28 | |||
29 | /** |
||
30 | * Impersonator constructor. |
||
31 | * |
||
32 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
33 | */ |
||
34 | 44 | public function __construct(Application $app) |
|
38 | |||
39 | /* ----------------------------------------------------------------- |
||
40 | | Getters & Setters |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | /** |
||
45 | * Get the guard session instance. |
||
46 | * |
||
47 | * @return \Illuminate\Auth\AuthManager|\Arcanedev\LaravelImpersonator\Guard\SessionGuard |
||
48 | */ |
||
49 | 18 | protected function auth() |
|
53 | |||
54 | /** |
||
55 | * Get the session store instance. |
||
56 | * |
||
57 | * @return \Illuminate\Contracts\Session\Session |
||
58 | */ |
||
59 | 22 | protected function session() |
|
63 | |||
64 | /** |
||
65 | * Get the config repository. |
||
66 | * |
||
67 | * @return \Illuminate\Contracts\Config\Repository |
||
68 | */ |
||
69 | 34 | protected function config() |
|
73 | |||
74 | /** |
||
75 | * Get the event dispatcher. |
||
76 | * |
||
77 | * @return \Illuminate\Contracts\Events\Dispatcher |
||
78 | */ |
||
79 | 16 | protected function events() |
|
83 | |||
84 | /** |
||
85 | * Get the session key. |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | 24 | public function getSessionKey() |
|
93 | |||
94 | /** |
||
95 | * Get the impersonator id. |
||
96 | * |
||
97 | * @return int|null |
||
98 | */ |
||
99 | 18 | public function getImpersonatorId() |
|
103 | |||
104 | /* ----------------------------------------------------------------- |
||
105 | | Main Methods |
||
106 | | ----------------------------------------------------------------- |
||
107 | */ |
||
108 | |||
109 | /** |
||
110 | * Start the impersonation. |
||
111 | * |
||
112 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonater |
||
113 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
114 | * |
||
115 | * @return bool |
||
116 | */ |
||
117 | 24 | public function start(Impersonatable $impersonater, Impersonatable $impersonated) |
|
136 | |||
137 | /** |
||
138 | * Stop the impersonation. |
||
139 | * |
||
140 | * @return bool |
||
141 | */ |
||
142 | 14 | public function stop() |
|
162 | |||
163 | /** |
||
164 | * Clear the impersonation. |
||
165 | */ |
||
166 | 14 | public function clear() |
|
170 | |||
171 | /** |
||
172 | * Find a user by the given id. |
||
173 | * |
||
174 | * @param int|string $id |
||
175 | * |
||
176 | * @return \Arcanedev\LaravelImpersonator\Contracts\Impersonatable |
||
177 | * |
||
178 | * @throws \Exception |
||
179 | */ |
||
180 | 26 | public function findUserById($id) |
|
184 | |||
185 | /* ----------------------------------------------------------------- |
||
186 | | Check Functions |
||
187 | | ----------------------------------------------------------------- |
||
188 | */ |
||
189 | |||
190 | /** |
||
191 | * Check if it's impersonating. |
||
192 | * |
||
193 | * @return bool |
||
194 | */ |
||
195 | 18 | public function isImpersonating() |
|
199 | |||
200 | /** |
||
201 | * Check if the impersonations is enabled. |
||
202 | * |
||
203 | * @return bool |
||
204 | */ |
||
205 | 24 | public function isEnabled() |
|
209 | |||
210 | /* ----------------------------------------------------------------- |
||
211 | | Other Methods |
||
212 | | ----------------------------------------------------------------- |
||
213 | */ |
||
214 | |||
215 | /** |
||
216 | * Check the impersonation. |
||
217 | * |
||
218 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonater |
||
219 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
220 | */ |
||
221 | 24 | private function checkImpersonation(Impersonatable $impersonater, Impersonatable $impersonated): void |
|
228 | |||
229 | /** |
||
230 | * Check if the impersonation is enabled. |
||
231 | * |
||
232 | * @throws \Arcanedev\LaravelImpersonator\Exceptions\ImpersonationException |
||
233 | */ |
||
234 | 24 | private function mustBeEnabled(): void |
|
241 | |||
242 | /** |
||
243 | * Check the impersonater and the impersonated are different. |
||
244 | * |
||
245 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonater |
||
246 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
247 | * |
||
248 | * @throws \Arcanedev\LaravelImpersonator\Exceptions\ImpersonationException |
||
249 | */ |
||
250 | 22 | private function mustBeDifferentImpersonatable(Impersonatable $impersonater, Impersonatable $impersonated): void |
|
255 | |||
256 | /** |
||
257 | * Check the impersonater. |
||
258 | * |
||
259 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonater |
||
260 | * |
||
261 | * @throws \Arcanedev\LaravelImpersonator\Exceptions\ImpersonationException |
||
262 | */ |
||
263 | 20 | private function checkImpersonater(Impersonatable $impersonater): void |
|
268 | |||
269 | /** |
||
270 | * Check the impersonated. |
||
271 | * |
||
272 | * @param \Arcanedev\LaravelImpersonator\Contracts\Impersonatable|mixed $impersonated |
||
273 | * |
||
274 | * @throws \Arcanedev\LaravelImpersonator\Exceptions\ImpersonationException |
||
275 | */ |
||
276 | 18 | private function checkImpersonated(Impersonatable $impersonated): void |
|
282 | } |
||
283 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: