Role   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 45
rs 10
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B load() 0 30 8
1
<?php
2
3
namespace App\Tenant\Loader;
4
5
use App\EventListener\Entity\Role\PropagationListener;
6
use Ds\Component\Database\Util\Objects;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Database\Util\Objects 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...
7
use Ds\Component\Tenant\Entity\Tenant;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Tenant\Entity\Tenant 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
9
/**
10
 * Trait Role
11
 */
12
trait Role
13
{
14
    /**
15
     * @var \App\Service\RoleService
16
     */
17
    private $roleService;
18
19
    /**
20
     * @var string
21
     */
22
    private $path;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function load(Tenant $tenant)
28
    {
29
        $eventManager = $this->roleService->getManager()->getEventManager();
30
31
        foreach ($eventManager->getListeners() as $event => $listeners) {
32
            foreach ($listeners as $key => $listener) {
33
                if (is_object($listener) && $listener instanceof PropagationListener) {
34
                    $listener->setEnabled(false);
35
                } else if (is_string($listener) && $listener === PropagationListener::class) {
36
                    $eventManager->removeEventListener(['postPersist'], $listener);
37
                }
38
            }
39
        }
40
41
        $data = (array) json_decode(json_encode($tenant->getData()));
42
        $objects = Objects::parseFile($this->path, $data);
43
        $manager = $this->roleService->getManager();
44
45
        foreach ($objects as $object) {
46
            $role = $this->roleService->createInstance();
47
            $role
48
                ->setUuid($object->uuid)
49
                ->setOwner($object->owner)
50
                ->setOwnerUuid($object->owner_uuid)
51
                ->setSlug($object->slug)
52
                ->setTitle((array) $object->title)
53
                ->setPermissions((array) $object->permissions)
54
                ->setTenant($object->tenant);
55
            $manager->persist($role);
56
            $manager->flush();
57
        }
58
    }
59
}
60