EndPointConfigurator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 33
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A configure() 0 9 4
1
<?php
2
3
namespace Parroauth2\Client\Factory;
4
5
use Parroauth2\Client\Client;
6
use Parroauth2\Client\ClientInterface;
7
use Parroauth2\Client\EndPoint\EndPointInterface;
8
9
/**
10
 * Configure endpoints for a client
11
 *
12
 * The configurator will check if the provider supports the endpoint, and then instantiate the endpoint
13
 */
14
final class EndPointConfigurator
15
{
16
    /**
17
     * @var array<string, class-string<EndPointInterface>|callable(ClientInterface):EndPointInterface>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string, class-stri...ace):EndPointInterface> at position 4 could not be parsed: Unknown type name 'class-string' at position 4 in array<string, class-string<EndPointInterface>|callable(ClientInterface):EndPointInterface>.
Loading history...
18
     */
19
    private $endpoints;
20
21
22
    /**
23
     * EndPointConfigurator constructor.
24
     *
25
     * @param array<string, class-string<EndPointInterface>|callable(ClientInterface):EndPointInterface> $endpoints
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string, class-stri...ace):EndPointInterface> at position 4 could not be parsed: Unknown type name 'class-string' at position 4 in array<string, class-string<EndPointInterface>|callable(ClientInterface):EndPointInterface>.
Loading history...
26
     *     Map of endpoint class name or factory, indexed by the endpoint name
27
     */
28 196
    public function __construct(array $endpoints)
29
    {
30 196
        $this->endpoints = $endpoints;
31 196
    }
32
33
    /**
34
     * Configure the endpoint on the client
35
     *
36
     * @param ClientInterface $client
37
     */
38 144
    public function configure(ClientInterface $client): void
39
    {
40 144
        foreach ($this->endpoints as $name => $endpoint) {
41 144
            if (!$client->provider()->supportsEndpoint($name)) {
42 4
                continue;
43
            }
44
45 144
            $endpoint = is_callable($endpoint) ? $endpoint($client) : new $endpoint($client);
46 144
            $client->endPoints()->add($endpoint);
47
        }
48 144
    }
49
}
50