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

Registration::load()   B

Complexity

Conditions 8
Paths 10

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 20
nc 10
nop 1
dl 0
loc 30
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
namespace App\Fixture;
4
5
use App\Entity\Registration as RegistrationEntity;
6
use App\EventListener\Entity\Registration\UserListener;
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
10
/**
11
 * Trait Registration
12
 */
13
trait Registration
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
        $eventManager = $manager->getEventManager();
28
29
        foreach ($eventManager->getListeners() as $event => $listeners) {
30
            foreach ($listeners as $key => $listener) {
31
                if (is_object($listener) && $listener instanceof UserListener) {
32
                    $listener->setEnabled(false);
33
                } else if (is_string($listener) && $listener === UserListener::class) {
34
                    $eventManager->removeEventListener(['postPersist'], $listener);
35
                }
36
            }
37
        }
38
39
        $objects = $this->parse($this->path);
40
41
        foreach ($objects as $object) {
42
            $registration = new RegistrationEntity;
43
            $registration
44
                ->setUuid($object->uuid)
45
                ->setOwner($object->owner)
46
                ->setOwnerUuid($object->owner_uuid)
47
                ->setUsername($object->username)
48
                ->setPassword($object->password)
49
                ->setData($object->data)
50
                ->setTenant($object->tenant);
51
            $manager->persist($registration);
52
        }
53
54
        $manager->flush();
55
    }
56
}
57