RemoteProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 35
ccs 12
cts 15
cp 0.8
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isAllowedUri() 0 3 1
A fetch() 0 17 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\Issuer\Metadata\Provider;
6
7
use function array_filter;
8
use Facile\OpenIDClient\Exception\ExceptionInterface;
9
use Facile\OpenIDClient\Exception\RuntimeException;
10
11
final class RemoteProvider implements RemoteProviderInterface
12
{
13
    /** @var RemoteProviderInterface[] */
14
    private $providers;
15
16
    /**
17
     * @param RemoteProviderInterface[] $providers
18
     */
19 3
    public function __construct(array $providers)
20
    {
21 3
        $this->providers = $providers;
22 3
    }
23
24
    public function isAllowedUri(string $uri): bool
25
    {
26
        return true;
27
    }
28
29 3
    public function fetch(string $uri): array
30
    {
31 3
        $lastException = null;
32
33 3
        $providers = array_filter($this->providers, static function (RemoteProviderInterface $provider) use ($uri): bool {
34 3
            return $provider->isAllowedUri($uri);
35 3
        });
36
37 3
        foreach ($providers as $provider) {
38
            try {
39 3
                return $provider->fetch($uri);
40 1
            } catch (ExceptionInterface $e) {
41 1
                $lastException = $e;
42
            }
43
        }
44
45
        throw new RuntimeException('Unable to fetch issuer metadata', 0, $lastException);
46
    }
47
}
48