UriResolver::supports()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\WebFingerEndpoint\IdentifierResolver;
15
16
use Assert\Assertion;
17
use function League\Uri\parse;
18
19
final class UriResolver implements IdentifierResolver
20
{
21
    public function supports(string $resource): bool
22
    {
23
        $uri = parse($resource);
24
25
        return 'https' === $uri['scheme'] && null !== $uri['user'];
26
    }
27
28
    public function resolve(string $resource): Identifier
29
    {
30
        $uri = parse($resource);
31
        Assertion::string($uri['user'], 'Invalid resource.');
32
        Assertion::string($uri['host'], 'Invalid resource.');
33
34
        return new Identifier($uri['user'], $uri['host'], $uri['port']);
35
    }
36
}
37