Test Failed
Pull Request — master (#88)
by Artem
04:05
created

IdentityProviderResolver   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 55
rs 10
c 1
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B resolve() 0 33 7
1
<?php
2
3
namespace Slides\Saml2\Resolvers;
4
5
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Support\Facades\Log;
7
use Slides\Saml2\Contracts\IdentityProvidable;
8
use Slides\Saml2\Contracts\ResolvesIdentityProvider;
9
use Slides\Saml2\Repositories\IdentityProviderRepository;
10
11
class IdentityProviderResolver implements ResolvesIdentityProvider
12
{
13
    /**
14
     * @var IdentityProviderRepository
15
     */
16
    protected IdentityProviderRepository $repository;
17
18
    /**
19
     * @param IdentityProviderRepository $repository
20
     */
21
    public function __construct(IdentityProviderRepository $repository)
22
    {
23
        $this->repository = $repository;
24
    }
25
26
    /**
27
     * Resolve a tenant from the request.
28
     *
29
     * @param Request $request
30
     *
31
     * @return IdentityProvidable|null
32
     */
33
    public function resolve(Request $request): ?IdentityProvidable
34
    {
35
        if (!$uuid = $request->route('uuid')) {
36
            if (config('saml2.debug')) {
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

36
            if (/** @scrutinizer ignore-call */ config('saml2.debug')) {
Loading history...
37
                Log::debug('[Saml2] Identity Provider UUID is not present in the URL so cannot be resolved', [
38
                    'url' => $request->fullUrl()
39
                ]);
40
            }
41
42
            return null;
43
        }
44
45
        if (!$idp = $this->repository->findByUUID($uuid)) {
46
            if (config('saml2.debug')) {
47
                Log::debug('[Saml2] Identity Provider cannot be found', ['uuid' => $uuid]);
48
            }
49
50
            return null;
51
        }
52
53
        if ($idp->trashed()) {
54
            if (config('saml2.debug')) {
55
                Log::debug("[Saml2] Identity Provider #{$idp->id} resolved but marked as deleted", [
56
                    'id' => $idp->id,
57
                    'uuid' => $uuid,
58
                    'deleted_at' => $idp->deleted_at->toDateTimeString()
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

58
                    'deleted_at' => $idp->deleted_at->/** @scrutinizer ignore-call */ toDateTimeString()

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.

Loading history...
59
                ]);
60
            }
61
62
            return null;
63
        }
64
65
        return $idp;
66
    }
67
}
68