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

SQLiteForeignKeyEnabler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A preFlush() 0 11 2
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