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

UriResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

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