EventListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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