Failed Conditions
Push — ng ( 17df75...6face8 )
by Florent
04:09
created

UriPathResolver   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 10 4
A resolve() 0 9 3
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\Bundle\Tests\TestBundle\Service;
15
16
use function League\Uri\parse;
17
use OAuth2Framework\Component\IssuerDiscoveryEndpoint\IdentifierResolver\Identifier;
18
use OAuth2Framework\Component\IssuerDiscoveryEndpoint\IdentifierResolver\IdentifierResolver;
19
20
class UriPathResolver implements IdentifierResolver
21
{
22
    /**
23
     * @param string $resource_name
24
     *
25
     * @return bool
26
     */
27
    public function supports(string $resource_name): bool
28
    {
29
        $uri = parse($resource_name);
30
31
        return 'https' === $uri['scheme']
32
            && null === $uri['user']
33
            && null !== $uri['path']
34
            && '/+' === substr($uri['path'], 0, 2)
35
            ;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function resolve(string $resource_name): Identifier
42
    {
43
        $uri = parse($resource_name);
44
        if (!is_string($uri['path']) || !is_string($uri['host'])) {
45
            throw new \InvalidArgumentException('Invalid resource.');
46
        }
47
48
        return new Identifier(substr($uri['path'], 2), $uri['host'], $uri['port']);
49
    }
50
}