RegisterHttpClientPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\DAOBundle\DependencyInjection\Compiler;
6
7
use Buzz\Client\BuzzClientInterface;
8
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
11
12
final class RegisterHttpClientPass implements CompilerPassInterface
13
{
14
    private const HTTP_CLIENT_PARAMETER = 'setono_dao.http_client';
15
    private const HTTP_CLIENT_SERVICE_ID = 'setono_dao.http_client';
16
17
    public function process(ContainerBuilder $container): void
18
    {
19
        if ($container->hasParameter(self::HTTP_CLIENT_PARAMETER)) {
20
            if (!$container->has($container->getParameter(self::HTTP_CLIENT_PARAMETER))) {
0 ignored issues
show
Bug introduced by
It seems like $container->getParameter...:HTTP_CLIENT_PARAMETER) can also be of type array; however, parameter $id of Symfony\Component\Depend...ContainerBuilder::has() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

20
            if (!$container->has(/** @scrutinizer ignore-type */ $container->getParameter(self::HTTP_CLIENT_PARAMETER))) {
Loading history...
21
                throw new ServiceNotFoundException($container->getParameter(self::HTTP_CLIENT_PARAMETER));
22
            }
23
24
            $container->setAlias(self::HTTP_CLIENT_SERVICE_ID, $container->getParameter(self::HTTP_CLIENT_PARAMETER));
0 ignored issues
show
Bug introduced by
It seems like $container->getParameter...:HTTP_CLIENT_PARAMETER) can also be of type array; however, parameter $id of Symfony\Component\Depend...inerBuilder::setAlias() does only seem to accept Symfony\Component\DependencyInjection\Alias|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

24
            $container->setAlias(self::HTTP_CLIENT_SERVICE_ID, /** @scrutinizer ignore-type */ $container->getParameter(self::HTTP_CLIENT_PARAMETER));
Loading history...
25
        } elseif ($container->has(BuzzClientInterface::class)) {
26
            $container->setAlias(self::HTTP_CLIENT_SERVICE_ID, BuzzClientInterface::class);
27
        }
28
    }
29
}
30