EventListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 35
c 0
b 0
f 0
ccs 0
cts 17
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A reconnectToDatabase() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Adgoal\DBALFaultTolerance\Events;
6
7
use Adgoal\DBALFaultTolerance\Events\Args\ReconnectEventArgs;
8
use Doctrine\Common\EventSubscriber;
9
use Psr\Log\LoggerInterface;
10
11
/**
12
 * Class EventListener.
13
 */
14
class EventListener implements EventSubscriber
15
{
16
    /**
17
     * @var LoggerInterface
18
     */
19
    private $logger;
20
21
    public function __construct(LoggerInterface $logger)
22
    {
23
        $this->logger = $logger;
24
    }
25
26
    /**
27
     * Returns an array of events this subscriber wants to listen to.
28
     *
29
     * @return string[]
30
     */
31
    public function getSubscribedEvents(): array
32
    {
33
        return [
34
            Events::RECONNECT_TO_DATABASE,
35
        ];
36
    }
37
38
    /**
39
     * @param ReconnectEventArgs $args
40
     */
41
    public function reconnectToDatabase(ReconnectEventArgs $args): void
42
    {
43
        $this->logger->debug(
44
            '[DOCTRINE][{function}] Retrying query (attempt {attempt}): {query}',
45
            ['function' => $args->getFunction(), 'attempt' => $args->getAttempt(), 'query' => $args->getQuery()]
46
        );
47
    }
48
}
49