Passed
Pull Request — develop (#54)
by Mario
01:55
created

OrganizationRole::load()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 37
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 23
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 37
rs 9.2408
1
<?php
2
3
namespace App\Fixture;
4
5
use App\Entity\OrganizationRole as OrganizationRoleEntity;
6
use DateTime;
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
use LogicException;
10
11
/**
12
 * Trait OrganizationRole
13
 */
14
trait OrganizationRole
15
{
16
    use Yaml;
17
18
    /**
19
     * @var string
20
     */
21
    private $path;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function load(ObjectManager $manager)
27
    {
28
        $objects = $this->parse($this->path);
29
30
        foreach ($objects as $object) {
31
            $organization = $this->getReference($object->organization);
32
33
            if (!$organization) {
34
                throw new LogicException('Organization "'.$object->organization.'" does not exist.');
35
            }
36
37
            $organizationRole = new OrganizationRoleEntity;
38
            $organizationRole
39
                ->setOrganization($organization)
40
                ->setUuid($object->uuid)
41
                ->setOwner($object->owner)
42
                ->setOwnerUuid($object->owner_uuid)
43
                ->setEntityUuids((array) $object->entity_uuids)
44
                ->setTenant($object->tenant);
45
46
            if (null !== $object->created_at) {
47
                $date = new DateTime;
48
                $date->setTimestamp($object->created_at);
49
                $organizationRole->setCreatedAt($date);
50
            }
51
52
            $role = $this->getReference($object->role);
53
54
            if (!$role) {
55
                throw new LogicException('Role "'.$object->role.'" does not exist.');
56
            }
57
58
            $organizationRole->setRole($role);
59
            $manager->persist($organizationRole);
60
        }
61
62
        $manager->flush();
63
    }
64
}
65