Completed
Push — master ( 18c7f8...c29312 )
by Tobias
10:28
created

LoggerSubscriber   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 21.43%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 46
ccs 3
cts 14
cp 0.2143
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 7 1
A onPreRun() 0 6 2
A onPostRun() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Neo4j\Neo4jBundle\EventSubscriber;
6
7
use GraphAware\Neo4j\Client\Event\PostRunEvent;
8
use GraphAware\Neo4j\Client\Event\PreRunEvent;
9
use GraphAware\Neo4j\Client\Neo4jClientEvents;
10
use Neo4j\Neo4jBundle\Collector\QueryLogger;
11
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
12
13
class LoggerSubscriber implements EventSubscriberInterface
14
{
15
    /**
16
     * @var QueryLogger
17
     */
18
    private $queryLogger;
19
20
    /**
21
     * @param QueryLogger $queryLogger
22
     */
23
    public function __construct(QueryLogger $queryLogger)
24
    {
25
        $this->queryLogger = $queryLogger;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    public static function getSubscribedEvents()
32
    {
33
        return [
34 1
            Neo4jClientEvents::NEO4J_PRE_RUN => 'onPreRun',
35 1
            Neo4jClientEvents::NEO4J_POST_RUN => 'onPostRun',
36
        ];
37
    }
38
39
    /**
40
     * @param PreRunEvent $event
41
     */
42
    public function onPreRun(PreRunEvent $event)
43
    {
44
        foreach ($event->getStatements() as $statement) {
45
            $this->queryLogger->record($statement);
46
        }
47
    }
48
49
    /**
50
     * @param PostRunEvent $event
51
     */
52
    public function onPostRun(PostRunEvent $event)
53
    {
54
        foreach ($event->getResults() as $result) {
55
            $this->queryLogger->finish($result);
56
        }
57
    }
58
}
59