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

UserFixture::load()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 39
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 28
nc 16
nop 1
dl 0
loc 39
rs 8.8497
c 0
b 0
f 0
1
<?php
2
3
namespace AppBundle\Fixture;
4
5
use AppBundle\Entity\User;
6
use AppBundle\EventListener\User\IdentityListener;
7
use Doctrine\Common\Persistence\ObjectManager;
8
use Ds\Component\Database\Fixture\ResourceFixture;
9
10
/**
11
 * Class UserFixture
12
 */
13
abstract class UserFixture extends ResourceFixture
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function load(ObjectManager $manager)
19
    {
20
        $metadata = $manager->getClassMetadata(User::class);
21
22
        foreach ($metadata->entityListeners as $event => $listeners) {
23
            foreach ($listeners as $key => $listener) {
24
                if (IdentityListener::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_user_id_seq RESTART WITH 1');
36
                break;
37
        }
38
39
        $userManager = $this->container->get('fos_user.user_manager');
40
        $objects = $this->parse($this->getResource());
41
42
        foreach ($objects as $object) {
43
            $user = $userManager->createUser();
44
            $user
45
                ->setUuid($object->uuid)
46
                ->setUsername($object->username)
47
                ->setEmail($object->email)
48
                ->setPlainPassword($object->password)
49
                ->setRoles($object->roles)
50
                ->setOwner($object->owner)
51
                ->setOwnerUuid($object->owner_uuid)
52
                ->setIdentity($object->identity)
53
                ->setIdentityUuid($object->identity_uuid)
54
                ->setEnabled($object->enabled)
55
                ->setTenant($object->tenant);
56
            $userManager->updateUser($user);
57
        }
58
    }
59
}
60