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

SqliteSessionInit::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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