Passed
Push — develop ( a3ce46...991cd4 )
by Florian
12:29
created

UrlBuilderLocator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\UrlBuilder;
4
5
use App\Enum\Provider;
6
use App\Exception\UrlBuilderNotFoundException;
7
use Psr\Container\ContainerInterface;
8
use Symfony\Contracts\Service\ServiceSubscriberInterface;
9
10
class UrlBuilderLocator implements ServiceSubscriberInterface
11
{
12
    public function __construct(
13
        private ContainerInterface $locator
14
    ) {}
15
16
    /**
17
     * {@inheritDoc}
18
     */
19 1
    public static function getSubscribedServices(): array
20
    {
21
        return [
22 1
            Provider::BIENICI               => BienIciUrlBuilder::class,
23
            Provider::LEBONCOIN             => LeBonCoinUrlBuilder::class,
24
            Provider::LOGIC_IMMO            => LogicImmoUrlBuilder::class,
25
            Provider::LOGIC_IMMO_NEUF       => LogicImmoNeufUrlBuilder::class,
26
            Provider::OUESTFRANCE_IMMO      => OuestFranceImmoUrlBuilder::class,
27
            Provider::OUESTFRANCE_IMMO_NEUF => OuestFranceImmoNeufUrlBuilder::class,
28
            Provider::PAP                   => PapUrlBuilder::class,
29
            Provider::PAP_NEUF              => PapNeufUrlBuilder::class,
30
            Provider::SELOGER               => SeLogerUrlBuilder::class,
31
            Provider::SELOGER_NEUF          => SeLogerNeufUrlBuilder::class,
32
            Provider::SUPERIMMO             => SuperimmoUrlBuilder::class,
33
            Provider::SUPERIMMO_NEUF        => SuperimmoNeufUrlBuilder::class
34
        ];
35
    }
36
37
    /**
38
     * @throws UrlBuilderNotFoundException
39
     */
40
    public function get(string $provider): UrlBuilderInterface
41
    {
42
        if (!$this->locator->has($provider)) {
43
            throw new UrlBuilderNotFoundException('No URL builder found for the provider: ' . $provider);
44
        }
45
46
        return $this->locator->get($provider);
47
    }
48
}
49