Completed
Push — master ( 19fab1...ec2cfc )
by ANTHONIUS
23s queued 11s
created

SessionPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 15%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 32
ccs 3
cts 20
cp 0.15
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createLocalSession() 0 18 1
A process() 0 8 3
1
<?php
2
3
4
namespace Doyo\Bridge\CodeCoverage\Compiler;
5
6
7
use Doyo\Bridge\CodeCoverage\Listener\LocalListener;
8
use Doyo\Bridge\CodeCoverage\Session\LocalSession;
9
use Doyo\Bridge\CodeCoverage\Session\RemoteSession;
10
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\DependencyInjection\Definition;
13
use Symfony\Component\DependencyInjection\Reference;
14
15
class SessionPass implements CompilerPassInterface
16
{
17 35
    public function process(ContainerBuilder $container)
18
    {
19 35
        $sessions = $container->getParameterBag()->get('sessions');
20
21 35
        foreach($sessions as $name => $config){
22
            $driver = $config['driver'];
23
            if('local' === $driver){
24
                $this->createLocalSession($container, $name, $config);
25
            }
26
        }
27
    }
28
29
    private function createLocalSession(ContainerBuilder $container, string $name, array $config)
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

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

29
    private function createLocalSession(ContainerBuilder $container, string $name, /** @scrutinizer ignore-unused */ array $config)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        $id = 'sessions.'.$name;
32
        $sessionId = $id.'.session';
33
        $listenerId = $id.'.listener';
34
35
        $session = new Definition(LocalSession::class);
36
        $session->addArgument($name);
37
        $session->addTag('coverage.session');
38
        $session->addMethodCall('init',[$container->getParameter('config')]);
39
        $container->setDefinition($sessionId, $session);
40
41
        $listener = new Definition(LocalListener::class);
42
        $listener->addArgument(new Reference($sessionId));
43
        $container->setDefinition($listenerId, $listener);
44
45
        $dispatcher = $container->findDefinition('coverage');
46
        $dispatcher->addMethodCall('addSubscriber',[new Reference($listenerId)]);
47
    }
48
}
49