Completed
Push — master ( fee4f6...5610d2 )
by Kevin
01:29
created

DoctrineDbal::check()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 7
cp 0
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Liip\MonitorBundle\Check;
4
5
use Doctrine\Persistence\ConnectionRegistry;
6
use Laminas\Diagnostics\Check\AbstractCheck;
7
use Laminas\Diagnostics\Result\Success;
8
9
class DoctrineDbal extends AbstractCheck
10
{
11
    protected $manager;
12
    protected $connectionName;
13
14 4
    public function __construct(ConnectionRegistry $registry, $connectionName = null)
15
    {
16 4
        $this->manager = $registry;
17 4
        $this->connectionName = $connectionName;
18 4
    }
19
20
    public function check()
21
    {
22
        $connection = $this->manager->getConnection($this->connectionName);
23
        $query = $connection->getDriver()->getDatabasePlatform()->getDummySelectSQL();
24
25
        // after dbal 2.11 fetchOne replace fetchColumn
26
        if (method_exists($connection, 'fetchOne')) {
27
            $connection->fetchOne($query);
28
        } else {
29
            $connection->fetchColumn($query);
30
        }
31
32
        return new Success();
33
    }
34
}
35