GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ConnectionListener::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0116
1
<?php
2
3
namespace Bernard\Driver\Doctrine;
4
5
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6
use Doctrine\DBAL\DBALException;
7
8
/**
9
 * Inspired by Swarrots ConnectionProcessor (https://github.com/swarrot/swarrot/blob/master/src/Swarrot/Processor/Doctrine/ConnectionProcessor.php).
10
 *
11
 * @author Markus Bachmann <[email protected]>
12
 */
13
class ConnectionListener implements EventSubscriberInterface
14
{
15
    /**
16
     * @var Connection[]
17
     */
18
    private $connections;
19
20
    public static function getSubscribedEvents()
21
    {
22
        return [
23
            'bernard.invoke' => 'onPing',
24
        ];
25
    }
26
27 3
    public function __construct($connections)
28
    {
29 3
        if (!is_array($connections)) {
30 3
            $connections = [$connections];
31 3
        }
32
33 3
        $this->connections = $connections;
34 3
    }
35
36 3
    public function onPing()
37
    {
38 3
        foreach ($this->connections as $connection) {
39 3
            if (!$connection->isConnected()) {
40 1
                continue;
41
            }
42
43
            try {
44 2
                $connection->query($connection->getDatabasePlatform()->getDummySelectSQL());
45 2
            } catch (DBALException $e) {
46 1
                $connection->close(); // close timed out connections so that using them connects again
47
            }
48 3
        }
49 3
    }
50
}
51