OrganizationRole::load()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 41
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 23
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 41
rs 8.9297
1
<?php
2
3
namespace App\Fixture;
4
5
use App\Entity\OrganizationRole as OrganizationRoleEntity;
6
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...
7
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...
8
use LogicException;
9
10
/**
11
 * Trait OrganizationRole
12
 */
13
trait OrganizationRole
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
        $objects = $this->parse($this->path);
28
29
        foreach ($objects as $object) {
30
            $organization = $this->getReference($object->organization);
31
32
            if (!$organization) {
33
                throw new LogicException('Organization "'.$object->organization.'" does not exist.');
34
            }
35
36
            $organizationRole = new OrganizationRoleEntity;
37
            $organizationRole
38
                ->setOrganization($organization)
39
                ->setUuid($object->uuid)
40
                ->setOwner($object->owner)
41
                ->setOwnerUuid($object->owner_uuid)
42
                ->setTenant($object->tenant);
43
44
            $role = $this->getReference($object->role);
45
46
            if (!$role) {
47
                throw new LogicException('Role "'.$object->role.'" does not exist.');
48
            }
49
50
            $organizationRole->setRole($role);
51
52
            foreach ($object->business_units as $uuid) {
53
                $businessUnit = $this->getReference($uuid);
54
55
                if (!$businessUnit) {
56
                    throw new LogicException('Business Unit "'.$uuid.'" does not exist.');
57
                }
58
59
                $organizationRole->addBusinessUnit($businessUnit);
60
            }
61
62
            $manager->persist($organizationRole);
63
        }
64
65
        $manager->flush();
66
    }
67
}
68