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
Pull Request — master (#278)
by Henrik
08:37 queued 06:49
created

ConnectionListener::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Bernard\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 [
24
            'bernard.invoke' => 'onPing',
25
        ];
26
    }
27
28
    public function __construct($connections)
29
    {
30
        if (!is_array($connections)) {
31
            $connections = [$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