Failed Conditions
Push — master ( b8d841...bc596e )
by Florent
28:20
created

UriPathResolver::supports()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 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\WebFingerBundle\Tests\TestBundle\Service;
15
16
use OAuth2Framework\Component\WebFingerEndpoint\IdentifierResolver\Identifier;
17
use OAuth2Framework\Component\WebFingerEndpoint\IdentifierResolver\IdentifierResolver;
18
use function League\Uri\parse;
19
20
class UriPathResolver implements IdentifierResolver
21
{
22
    public function supports(string $resource_name): bool
23
    {
24
        $uri = parse($resource_name);
25
26
        return 'https' === $uri['scheme']
27
            && null === $uri['user']
28
            && null !== $uri['path']
29
            && '/+' === \mb_substr($uri['path'], 0, 2)
30
            ;
31
    }
32
33
    public function resolve(string $resource_name): Identifier
34
    {
35
        $uri = parse($resource_name);
36
        if (!\is_string($uri['path']) || !\is_string($uri['host'])) {
37
            throw new \InvalidArgumentException('Invalid resource.');
38
        }
39
40
        return new Identifier(\mb_substr($uri['path'], 2), $uri['host'], $uri['port']);
41
    }
42
}
43