Passed
Push — develop ( d38868...21087d )
by Mario
01:26
created

User::load()   B

Complexity

Conditions 8
Paths 10

Size

Total Lines 32
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 24
nc 10
nop 1
dl 0
loc 32
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
namespace App\Tenant\Loader;
4
5
use App\EventListener\Entity\User\IdentityListener;
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 User
11
 */
12
trait User
13
{
14
    /**
15
     * @var \App\Service\UserService
16
     */
17
    private $userService;
18
19
    /**
20
     * @var string
21
     */
22
    private $path;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function load(Tenant $tenant)
28
    {
29
        $eventManager = $this->userService->getManager()->getEventManager();
30
31
        foreach ($eventManager->getListeners() as $event => $listeners) {
32
            foreach ($listeners as $key => $listener) {
33
                if (is_object($listener) && $listener instanceof IdentityListener) {
34
                    $listener->setEnabled(false);
35
                } else if (is_string($listener) && $listener === IdentityListener::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->userService->getCustomManager();
44
45
        foreach ($objects as $object) {
46
            $user = $manager->createUser();
47
            $user
48
                ->setUsername($object->username)
49
                ->setEmail($object->email)
50
                ->setPlainPassword($object->password)
51
                ->setRoles($object->roles)
52
                ->setOwner($object->owner)
53
                ->setOwnerUuid($object->owner_uuid)
54
                ->setIdentity($object->identity)
55
                ->setIdentityUuid($object->identity_uuid)
56
                ->setEnabled($object->enabled)
57
                ->setTenant($object->tenant);
58
            $manager->updateUser($user);
59
        }
60
    }
61
}
62