Failed Conditions
Pull Request — master (#2836)
by
unknown
14:05
created

SqliteSessionInit::postConnect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 10
cc 2
nc 2
nop 1
crap 2.032
1
<?php declare(strict_types=1);
2
3
namespace Doctrine\DBAL\Event\Listeners;
4
5
use Doctrine\Common\EventSubscriber;
6
use Doctrine\DBAL\Event\ConnectionEventArgs;
7
use Doctrine\DBAL\Events;
8
use Doctrine\DBAL\Platforms\SqlitePlatform;
9
10
/**
11
 * Sqlite session init event subscriber enables foreign key constraints.
12
 */
13
final class SqliteSessionInit implements EventSubscriber
14
{
15 50
    public function postConnect(ConnectionEventArgs $args) : void
16
    {
17 50
        $args->getConnection()->exec('PRAGMA foreign_keys = on');
18
19 50
        if (! ($args->getDatabasePlatform() instanceof SqlitePlatform)) {
20 50
            return;
21
        }
22
23
        $args->getDatabasePlatform()->enableForeignKeyConstraintsSupport();
24
    }
25
26
    /**
27
     * @return string[]
28
     */
29 28
    public function getSubscribedEvents() : array
30
    {
31 28
        return [Events::postConnect];
32
    }
33
}
34