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::onPing()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.4661

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 13
cp 0.6923
rs 9.7998
c 0
b 0
f 0
cc 4
nc 4
nop 0
crap 4.4661
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