Passed
Push — develop ( 5d2696...713da0 )
by Mario
01:29
created

StaffRole::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 15
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 18
rs 9.7666
1
<?php
2
3
namespace App\Tenant\Loader\Identity;
4
5
use App\Entity\Staff as StaffEntity;
6
use App\Entity\Role as RoleEntity;
7
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...
8
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...
9
10
/**
11
 * Trait StaffRole
12
 */
13
trait StaffRole
14
{
15
    /**
16
     * @var \App\Service\StaffRoleService
17
     */
18
    private $staffRoleService;
19
20
    /**
21
     * @var string
22
     */
23
    private $path;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function load(Tenant $tenant)
29
    {
30
        $data = (array) json_decode(json_encode($tenant->getData()));
31
        $objects = Objects::parseFile($this->path, $data);
32
        $manager = $this->staffRoleService->getManager();
33
34
        foreach ($objects as $object) {
35
            $staff = $manager->getRepository(StaffEntity::class)->findOneBy(['uuid' => $object->staff]);
36
            $role = $manager->getRepository(RoleEntity::class)->findOneBy(['uuid' => $object->role]);
37
            $staffRole = $this->staffRoleService->createInstance();
38
            $staffRole
39
                ->setStaff($staff)
40
                ->setOwner($object->owner)
41
                ->setOwnerUuid($object->owner_uuid)
42
                ->setRole($role)
43
                ->setTenant($object->tenant);
44
            $manager->persist($staffRole);
45
            $manager->flush();
46
        }
47
    }
48
}
49