RemoteProvider::isAllowedUri()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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