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   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 6 1
A __construct() 0 8 2
A onPing() 0 14 4
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