Role::load()   B
last analyzed

Complexity

Conditions 8
Paths 10

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 22
nc 10
nop 1
dl 0
loc 32
rs 8.4444
c 1
b 0
f 0
1
<?php
2
3
namespace App\Fixture;
4
5
use App\Entity\Role as RoleEntity;
6
use App\EventListener\Entity\Role\PropagationListener;
7
use Doctrine\Common\Persistence\ObjectManager;
0 ignored issues
show
Bug introduced by
The type Doctrine\Common\Persistence\ObjectManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Ds\Component\Database\Fixture\Yaml;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Database\Fixture\Yaml was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
/**
11
 * Trait Role
12
 */
13
trait Role
14
{
15
    use Yaml;
16
17
    /**
18
     * @var string
19
     */
20
    private $path;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function load(ObjectManager $manager)
26
    {
27
        $eventManager = $manager->getEventManager();
28
29
        foreach ($eventManager->getListeners() as $event => $listeners) {
30
            foreach ($listeners as $key => $listener) {
31
                if (is_object($listener) && $listener instanceof PropagationListener) {
32
                    $listener->setEnabled(false);
33
                } else if (is_string($listener) && $listener === PropagationListener::class) {
34
                    $eventManager->removeEventListener(['postPersist'], $listener);
35
                }
36
            }
37
        }
38
39
        $objects = $this->parse($this->path);
40
41
        foreach ($objects as $object) {
42
            $role = new RoleEntity;
43
            $role
44
                ->setUuid($object->uuid)
45
                ->setOwner($object->owner)
46
                ->setOwnerUuid($object->owner_uuid)
47
                ->setTitle((array) $object->title)
48
                ->setSlug($object->slug)
49
                ->setData((array) $object->data)
50
                ->setPermissions((array) $object->permissions)
51
                ->setTenant($object->tenant);
52
            $manager->persist($role);
53
            $this->setReference($object->uuid, $role);
54
        }
55
56
        $manager->flush();
57
    }
58
}
59