Passed
Push — develop ( e1f02f...e3219b )
by Laurent
01:59
created

UserFixtures   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 18
c 0
b 0
f 0
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 19 1
A getGroups() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace User\Infrastructure\Doctrine\DataFixtures;
15
16
use Core\Domain\Common\Model\VO\EmailField;
17
use Core\Domain\Common\Model\VO\NameField;
18
use Core\Domain\Common\Model\VO\ResourceUuid;
19
use Doctrine\Bundle\FixturesBundle\Fixture;
0 ignored issues
show
Bug introduced by
The type Doctrine\Bundle\FixturesBundle\Fixture 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...
20
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
0 ignored issues
show
Bug introduced by
The type Doctrine\Bundle\Fixtures...e\FixtureGroupInterface 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...
21
use Doctrine\Persistence\ObjectManager;
0 ignored issues
show
Bug introduced by
The type Doctrine\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...
22
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...asswordEncoderInterface 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...
23
use User\Domain\Model\User;
24
use User\Domain\Model\VO\Password;
25
use User\Infrastructure\Doctrine\Entity\User as UserEntity;
26
27
class UserFixtures extends Fixture implements FixtureGroupInterface
28
{
29
    private UserPasswordEncoderInterface $passwordEncoder;
30
31
    public function __construct(UserPasswordEncoderInterface $passwordEncoder)
32
    {
33
        $this->passwordEncoder = $passwordEncoder;
34
    }
35
36
    public function load(ObjectManager $manager): void
37
    {
38
        $user = new User(
39
            ResourceUuid::fromString('a136c6fe-8f6e-45ed-91bc-586374791033'),
40
            NameField::fromString('Laurent'),
41
            EmailField::fromString('[email protected]'),
42
            Password::fromString('Password-1'),
43
            ['ROLE_ADMIN'],
44
        );
45
        $userSymfony = UserEntity::fromModel($user);
46
        $passwordEncoded = $this->passwordEncoder->encodePassword(
47
            $userSymfony,
48
            $user->password()->value()
49
        );
50
        $user->changePassword(Password::fromString($passwordEncoded));
51
        $userEntity = UserEntity::fromModel($user);
52
53
        $manager->persist($userEntity);
54
        $manager->flush();
55
    }
56
57
    public static function getGroups(): array
58
    {
59
        return ['user'];
60
    }
61
}
62