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

SystemRole::load()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 37
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 23
c 2
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\SystemRole as SystemRoleEntity;
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 SystemRole
13
 */
14
trait SystemRole
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
            $system = $this->getReference($object->system);
32
33
            if (!$system) {
34
                throw new LogicException('System "'.$object->system.'" does not exist.');
35
            }
36
37
            $systemRole = new SystemRoleEntity;
38
            $systemRole
39
                ->setSystem($system)
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
                $systemRole->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
            $systemRole->setRole($role);
59
            $manager->persist($systemRole);
60
        }
61
62
        $manager->flush();
63
    }
64
}
65