Passed
Push — main ( 4383ba...3025dd )
by Slawomir
04:44
created

SqliteForeignKeyEnabler::postConnect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace App\Infrastructure\Services\SqliteForeignKeyEnabler;
4
5
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
6
use Doctrine\DBAL\Event\ConnectionEventArgs;
7
use Doctrine\DBAL\Events;
8
9
class SqliteForeignKeyEnabler implements EventSubscriberInterface
10
{
11
    public function getSubscribedEvents(): array
12
    {
13
        return [Events::postConnect];
14
    }
15
16
    public function postConnect(ConnectionEventArgs $args): void
17
    {
18
        if (strtolower($args->getConnection()->getDatabasePlatform()->getName()) !== 'sqlite') {
19
            return;
20
        }
21
        $args->getConnection()->exec('PRAGMA foreign_keys = ON;');
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Connection::exec() has been deprecated: This API is deprecated and will be removed after 2022 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

21
        /** @scrutinizer ignore-deprecated */ $args->getConnection()->exec('PRAGMA foreign_keys = ON;');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
22
    }
23
}