Completed
Push — master ( 0c1714...bbfa1f )
by Artem
01:41
created

RegisterCentrifugoPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 21 3
1
<?php
2
/*
3
 * This file is part of the FreshCentrifugoBundle.
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Fresh\CentrifugoBundle\DependencyInjection\Compiler;
14
15
use Fresh\CentrifugoBundle\Logger\CommandHistoryLogger;
16
use Fresh\CentrifugoBundle\Service\Centrifugo;
17
use Fresh\CentrifugoBundle\Service\CentrifugoChecker;
18
use Fresh\CentrifugoBundle\Service\CentrifugoInterface;
19
use Fresh\CentrifugoBundle\Service\FakeCentrifugo;
20
use Fresh\CentrifugoBundle\Service\ResponseProcessor;
21
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
22
use Symfony\Component\DependencyInjection\ContainerBuilder;
23
use Symfony\Component\DependencyInjection\Definition;
24
25
/**
26
 * RegisterCentrifugoPass.
27
 *
28
 * @author Artem Henvald <[email protected]>
29
 */
30
class RegisterCentrifugoPass implements CompilerPassInterface
31
{
32
    /**
33
     * @param ContainerBuilder $container
34
     */
35
    public function process(ContainerBuilder $container): void
36
    {
37
        if (true === $container->getParameter('centrifugo.fake_mode')) {
38
            $definition = new Definition(FakeCentrifugo::class, []);
39
        } else {
40
            $definition = new Definition(
41
                Centrifugo::class,
42
                [
43
                    $container->resolveEnvPlaceholders('%env(CENTRIFUGO_API_ENDPOINT)%'),
44
                    $container->resolveEnvPlaceholders('%env(CENTRIFUGO_API_KEY)%'),
45
                    $container->findDefinition('http_client'),
46
                    $container->findDefinition(ResponseProcessor::class),
47
                    $container->findDefinition(CommandHistoryLogger::class),
48
                    $container->findDefinition(CentrifugoChecker::class),
49
                    $container->hasDefinition('profiler') ? $container->getDefinition('profiler') : null,
50
                ]
51
            );
52
        }
53
54
        $container->setDefinition(CentrifugoInterface::class, $definition);
55
    }
56
}
57