Cancelled
Push — develop ( 5a5c91...8665a3 )
by Florian
33s queued 10s
created

ProviderRepository::getProvidersByMainProvider()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Repository;
4
5
use App\DTO\Provider;
6
use Symfony\Component\Serializer\SerializerInterface;
7
use function array_filter;
8
9
class ProviderRepository
10
{
11
    /** @var Provider[] */
12
    private array $providers;
13
14
    /**
15
     * @param array               $providers
16
     * @param SerializerInterface $serializer
17
     */
18
    public function __construct(array $providers, SerializerInterface $serializer)
19
    {
20
        $this->providers = $serializer->denormalize($providers, Provider::class . '[]');
21
    }
22
23
    /**
24
     * @param string $id
25
     *
26
     * @return Provider|null
27
     */
28
    public function find(string $id): ?Provider
29
    {
30
        return $this->providers[$id] ?? null;
31
    }
32
33
    /**
34
     * @param string $id
35
     *
36
     * @return Provider[]
37
     */
38
    public function getProvidersByMainProvider(string $id): array
39
    {
40
        return array_filter($this->providers, fn(Provider $provider) =>
41
            $id === $provider->getId() || $id === $provider->getParentProvider()
42
        );
43
    }
44
}
45