Completed
Pull Request — master (#828)
by Rafał
20:48 queued 09:21
created

SQLiteForeignKeyEnabler::preFlush()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SWP\Behat\EventSubscriber;
6
7
use Doctrine\Common\EventSubscriber;
8
use Doctrine\DBAL\Platforms\SqlitePlatform;
9
use Doctrine\ORM\EntityManagerInterface;
10
use Doctrine\ORM\Event\PreFlushEventArgs;
11
use Doctrine\ORM\Query\ResultSetMapping;
12
13
class SQLiteForeignKeyEnabler implements EventSubscriber
14
{
15
    /** @var EntityManagerInterface */
16
    private $manager;
17
18
    public function __construct(EntityManagerInterface $manager)
19
    {
20
        $this->manager = $manager;
21
    }
22
23
    public function getSubscribedEvents(): array
24
    {
25
        return [
26
            'preFlush',
27
        ];
28
    }
29
30
    public function preFlush(PreFlushEventArgs $args): void
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
        if (!$this->manager->getConnection()->getDatabasePlatform() instanceof SqlitePlatform) {
33
            return;
34
        }
35
36
        $this->manager
37
            ->createNativeQuery('PRAGMA foreign_keys = ON;', new ResultSetMapping())
38
            ->execute()
39
        ;
40
    }
41
}
42