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.
Completed
Push — master ( 1144b4...828920 )
by Márk
07:09 queued 04:40
created

ConnectionListener::onPing()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 0
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
 * @package Bernard
13
 */
14
class ConnectionListener implements EventSubscriberInterface
15
{
16
    /**
17
     * @var Connection[]
18
     */
19
    private $connections;
20
21
    public static function getSubscribedEvents()
22
    {
23
        return array(
24
            'bernard.invoke' => 'onPing',
25
        );
26
    }
27
28
    public function __construct($connections)
29
    {
30
        if (!is_array($connections)) {
31
            $connections = array($connections);
32
        }
33
34
        $this->connections = $connections;
35
    }
36
37
    public function onPing()
38
    {
39
        foreach ($this->connections as $connection) {
40
            if (!$connection->isConnected()) {
41
                continue;
42
            }
43
44
            try {
45
                $connection->query($connection->getDatabasePlatform()->getDummySelectSQL());
46
            } catch (DBALException $e) {
47
                $connection->close(); // close timed out connections so that using them connects again
48
            }
49
        }
50
    }
51
}
52