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

SqliteForeignKeyEnabler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 13
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A postConnect() 0 6 2
A getSubscribedEvents() 0 3 1
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
}