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

ProviderRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 33
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 3 1
A __construct() 0 3 1
A getProvidersByMainProvider() 0 4 2
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