Passed
Push — develop ( c158eb...11585d )
by Andrea
35:02
created

SqliteForeignKeyActivationSubscriber   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 21
ccs 3
cts 6
cp 0.5
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A postConnect() 0 6 2
A getSubscribedEvents() 0 4 1
1
<?php
2
3
namespace Cdf\BiCoreBundle\Subscriber;
4
5
use Doctrine\Common\EventSubscriber;
6
use Doctrine\DBAL\Event\ConnectionEventArgs;
7
use Doctrine\DBAL\Events;
8
9
class SqliteForeignKeyActivationSubscriber implements EventSubscriber
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function getSubscribedEvents()
15
    {
16
        return [
17
            Events::postConnect,
18
        ];
19
    }
20
    /**
21
     * @param ConnectionEventArgs $args
22
     * @throws \Doctrine\DBAL\DBALException
23
     */
24 40
    public function postConnect(ConnectionEventArgs $args)
25
    {
26 40
        if ('sqlite' !== strtolower($args->getDatabasePlatform()->getName())) {
27 40
            return;
28
        }
29
        $args->getConnection()->exec('PRAGMA foreign_keys = ON;');
30
    }
31
}
32