Completed
Push — develop ( bfb09c...3a5f86 )
by Mario
07:54
created

RegistrationFixture::load()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 35
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 24
nc 16
nop 1
dl 0
loc 35
rs 8.9137
c 0
b 0
f 0
1
<?php
2
3
namespace AppBundle\Fixture;
4
5
use AppBundle\Entity\Registration;
6
use AppBundle\EventListener\Registration\UserListener;
7
use Doctrine\Common\Persistence\ObjectManager;
8
use Ds\Component\Database\Fixture\ResourceFixture;
9
10
/**
11
 * Class RegistrationFixture
12
 */
13
abstract class RegistrationFixture extends ResourceFixture
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function load(ObjectManager $manager)
19
    {
20
        $metadata = $manager->getClassMetadata(Registration::class);
21
22
        foreach ($metadata->entityListeners as $event => $listeners) {
23
            foreach ($listeners as $key => $listener) {
24
                if (UserListener::class === $listener['class']) {
25
                    unset($metadata->entityListeners[$event][$key]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
26
                }
27
            }
28
        }
29
30
        $connection = $manager->getConnection();
0 ignored issues
show
Bug introduced by
The method getConnection() does not exist on Doctrine\Common\Persistence\ObjectManager. It seems like you code against a sub-type of said class. However, the method does not exist in Doctrine\Common\Persistence\ObjectManagerDecorator. Are you sure you never get one of those? ( Ignorable by Annotation )

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

30
        /** @scrutinizer ignore-call */ 
31
        $connection = $manager->getConnection();
Loading history...
31
        $platform = $connection->getDatabasePlatform()->getName();
32
33
        switch ($platform) {
34
            case 'postgresql':
35
                $connection->exec('ALTER SEQUENCE app_registration_id_seq RESTART WITH 1');
36
                break;
37
        }
38
39
        $objects = $this->parse($this->getResource());
40
41
        foreach ($objects as $object) {
42
            $registration = new Registration;
43
            $registration
44
                ->setUuid($object->uuid)
45
                ->setOwner($object->owner)
46
                ->setOwnerUuid($object->owner_uuid)
47
                ->setUsername($object->username)
48
                ->setPassword($object->password)
49
                ->setData($object->data)
50
                ->setTenant($object->tenant);
51
            $manager->persist($registration);
52
            $manager->flush();
53
        }
54
    }
55
}
56