RemoteProvider::fetch()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 0
loc 17
ccs 9
cts 10
cp 0.9
crap 3.009
rs 9.9666
c 1
b 0
f 0
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