Passed
Push — master ( f59089...907e2e )
by Julien
01:19 queued 12s
created

SdkClientRegistry::getSdkClientList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 1
cts 1
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Mapado\RestClientSdk;
6
7
use Mapado\RestClientSdk\Exception\SdkClientNotFoundException;
8
9
class SdkClientRegistry
10
{
11
    /** var array<string, SdkClient> $sdkClientList */
12
    private $sdkClientList;
13
14
    /**
15
     * @param array<string, SdkClient> $sdkClientList
16
     */
17
    public function __construct(array $sdkClientList)
18
    {
19 1
        $this->sdkClientList = $sdkClientList;
20 1
    }
21
22
    public function getSdkClient(string $name): SdkClient
23
    {
24 1
        $client = $this->sdkClientList[$name] ?? null;
25
26 1
        if (!$client) {
27 1
            throw new SdkClientNotFoundException(
28 1
                'Sdk client not found for name ' . $name
29
            );
30
        }
31
32 1
        return $client;
33
    }
34
35
    /**
36
     * @return array<SdkClient>
37
     */
38
    public function getSdkClientList(): array
39
    {
40 1
        return $this->sdkClientList;
41
    }
42
43
    public function getSdkClientForClass(string $entityClassname): SdkClient
44
    {
45 1
        foreach ($this->sdkClientList as $sdkClient) {
46 1
            if ($sdkClient->getMapping()->hasClassMetadata($entityClassname)) {
47 1
                return $sdkClient;
48
            }
49
        }
50
51 1
        throw new SdkClientNotFoundException(
52 1
            'Sdk client not found for entity class ' . $entityClassname
53
        );
54
    }
55
}
56