Completed
Push — develop ( 81fd29...ee1c82 )
by Mario
03:27
created

RoleFixture   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B load() 0 36 6
1
<?php
2
3
namespace AppBundle\Fixture;
4
5
use AppBundle\Entity\Role;
6
use AppBundle\EventListener\Entity\Role\AccessListener;
7
use Doctrine\Common\Persistence\ObjectManager;
8
use Ds\Component\Database\Fixture\ResourceFixture;
9
10
/**
11
 * Class RoleFixture
12
 */
13
abstract class RoleFixture extends ResourceFixture
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function load(ObjectManager $manager)
19
    {
20
        $metadata = $manager->getClassMetadata(Role::class);
21
22
        foreach ($metadata->entityListeners as $event => $listeners) {
23
            foreach ($listeners as $key => $listener) {
24
                if (AccessListener::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_role_id_seq RESTART WITH 1');
36
                $connection->exec('ALTER SEQUENCE app_role_trans_id_seq RESTART WITH 1');
37
                break;
38
        }
39
40
        $objects = $this->parse($this->getResource());
41
42
        foreach ($objects as $object) {
43
            $role = new Role;
44
            $role
45
                ->setUuid($object->uuid)
46
                ->setOwner($object->owner)
47
                ->setOwnerUuid($object->owner_uuid)
48
                ->setTitle((array) $object->title)
49
                ->setSlug($object->slug)
50
                ->setPermissions((array) $object->permissions)
51
                ->setTenant($object->tenant);
52
            $manager->persist($role);
53
            $manager->flush();
54
        }
55
    }
56
}
57