1 | <?php |
||||||
2 | |||||||
3 | namespace Slides\Saml2\Http\Middleware; |
||||||
4 | |||||||
5 | use Slides\Saml2\Repositories\TenantRepository; |
||||||
6 | use Illuminate\Support\Facades\Log; |
||||||
7 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||||||
0 ignored issues
–
show
|
|||||||
8 | use Slides\Saml2\OneLoginBuilder; |
||||||
9 | |||||||
10 | /** |
||||||
11 | * Class ResolveTenant |
||||||
12 | * |
||||||
13 | * @package Slides\Saml2\Http\Middleware |
||||||
14 | */ |
||||||
15 | class ResolveTenant |
||||||
16 | { |
||||||
17 | /** |
||||||
18 | * @var TenantRepository |
||||||
19 | */ |
||||||
20 | protected $tenants; |
||||||
21 | |||||||
22 | /** |
||||||
23 | * @var OneLoginBuilder |
||||||
24 | */ |
||||||
25 | protected $builder; |
||||||
26 | |||||||
27 | /** |
||||||
28 | * ResolveTenant constructor. |
||||||
29 | * |
||||||
30 | * @param TenantRepository $tenants |
||||||
31 | * @param OneLoginBuilder $builder |
||||||
32 | */ |
||||||
33 | public function __construct(TenantRepository $tenants, OneLoginBuilder $builder) |
||||||
34 | { |
||||||
35 | $this->tenants = $tenants; |
||||||
36 | $this->builder = $builder; |
||||||
37 | } |
||||||
38 | |||||||
39 | /** |
||||||
40 | * Handle an incoming request. |
||||||
41 | * |
||||||
42 | * @param \Illuminate\Http\Request $request |
||||||
0 ignored issues
–
show
The type
Illuminate\Http\Request was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
43 | * @param \Closure $next |
||||||
44 | * |
||||||
45 | * @throws NotFoundHttpException |
||||||
46 | * |
||||||
47 | * @return mixed |
||||||
48 | */ |
||||||
49 | public function handle($request, \Closure $next) |
||||||
50 | { |
||||||
51 | if(!$tenant = $this->resolveTenant($request)) { |
||||||
52 | throw new NotFoundHttpException(); |
||||||
53 | } |
||||||
54 | |||||||
55 | if (config('saml2.debug')) { |
||||||
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
56 | Log::debug('[Saml2] Tenant resolved', [ |
||||||
57 | 'uuid' => $tenant->uuid, |
||||||
58 | 'id' => $tenant->id, |
||||||
59 | 'key' => $tenant->key |
||||||
60 | ]); |
||||||
61 | } |
||||||
62 | |||||||
63 | session()->flash('saml2.tenant.uuid', $tenant->uuid); |
||||||
0 ignored issues
–
show
The function
session was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
64 | |||||||
65 | $this->builder |
||||||
66 | ->withTenant($tenant) |
||||||
67 | ->bootstrap(); |
||||||
68 | |||||||
69 | return $next($request); |
||||||
70 | } |
||||||
71 | |||||||
72 | /** |
||||||
73 | * Resolve a tenant by a request. |
||||||
74 | * |
||||||
75 | * @param \Illuminate\Http\Request $request |
||||||
76 | * |
||||||
77 | * @return \Slides\Saml2\Models\Tenant|null |
||||||
78 | */ |
||||||
79 | protected function resolveTenant($request) |
||||||
80 | { |
||||||
81 | if(!$uuid = $request->route('uuid')) { |
||||||
82 | if (config('saml2.debug')) { |
||||||
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
83 | Log::debug('[Saml2] Tenant UUID is not present in the URL so cannot be resolved', [ |
||||||
84 | 'url' => $request->fullUrl() |
||||||
85 | ]); |
||||||
86 | } |
||||||
87 | |||||||
88 | return null; |
||||||
89 | } |
||||||
90 | |||||||
91 | if(!$tenant = $this->tenants->findByUUID($uuid)) { |
||||||
92 | if (config('saml2.debug')) { |
||||||
93 | Log::debug('[Saml2] Tenant doesn\'t exist', [ |
||||||
94 | 'uuid' => $uuid |
||||||
95 | ]); |
||||||
96 | } |
||||||
97 | |||||||
98 | return null; |
||||||
99 | } |
||||||
100 | |||||||
101 | if($tenant->trashed()) { |
||||||
102 | if (config('saml2.debug')) { |
||||||
103 | Log::debug('[Saml2] Tenant #' . $tenant->id. ' resolved but marked as deleted', [ |
||||||
104 | 'id' => $tenant->id, |
||||||
105 | 'uuid' => $uuid, |
||||||
106 | 'deleted_at' => $tenant->deleted_at->toDateTimeString() |
||||||
0 ignored issues
–
show
The method
toDateTimeString() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
107 | ]); |
||||||
108 | } |
||||||
109 | |||||||
110 | return null; |
||||||
111 | } |
||||||
112 | |||||||
113 | return $tenant; |
||||||
114 | } |
||||||
115 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths