Issues (279)

api/src/Service/RegistrationService.php (3 issues)

Labels
Severity
1
<?php
2
3
namespace App\Service;
4
5
use App\Entity\Registration;
6
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
The type Doctrine\ORM\EntityManagerInterface 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\Config\Service\ConfigService;
0 ignored issues
show
The type Ds\Component\Config\Service\ConfigService 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\Entity\Service\EntityService;
0 ignored issues
show
The type Ds\Component\Entity\Service\EntityService 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
 * Class RegistrationService
12
 */
13
final class RegistrationService extends EntityService
14
{
15
    /**
16
     * @var \App\Service\UserService
17
     */
18
    private $userService;
19
20
    /**
21
     * @var \Ds\Component\Config\Service\ConfigService
22
     */
23
    private $configService;
24
25
    /**
26
     * Constructor
27
     *
28
     * @param \Doctrine\ORM\EntityManagerInterface $manager
29
     * @param \App\Service\UserService $userService
30
     * @param \Ds\Component\Config\Service\ConfigService $configService
31
     * @param string $entity
32
     */
33
    public function __construct(EntityManagerInterface $manager, UserService $userService, ConfigService $configService, string $entity = Registration::class)
34
    {
35
        parent::__construct($manager, $entity);
36
        $this->userService = $userService;
37
        $this->configService = $configService;
38
    }
39
40
    /**
41
     * Create user from a registration
42
     *
43
     * @param \App\Entity\Registration $registration
44
     * @return \App\Entity\User
45
     */
46
    public function createUser(Registration $registration)
47
    {
48
        $key = 'app.registration.'.strtolower($registration->getIdentity());
49
        $configs = [
50
            'roles' => $this->configService->get($key.'.roles'),
51
            'owner.type' => $this->configService->get($key.'.owner.type'),
52
            'owner.uuid' => $this->configService->get($key.'.owner.uuid'),
53
            'enabled' => $this->configService->get($key.'.enabled')
54
        ];
55
56
        $manager = $this->userService->getCustomManager();
57
        $user = $manager->createUser();
58
        $user
59
            ->setRegistration($registration)
60
            ->setUsername($registration->getUsername())
61
            ->setEmail($registration->getUsername())
62
            ->setPlainPassword($registration->getPassword())
63
            ->setRoles($configs['roles'])
64
            ->setOwner($configs['owner.type'])
65
            ->setOwnerUuid($configs['owner.uuid'])
66
            ->setIdentity($registration->getIdentity())
67
            ->setEnabled($configs['enabled']);
68
        $manager->updateUser($user);
69
70
        $registration->setUser($user);
71
        $this->manager->persist($registration);
72
        $this->manager->flush();
73
74
        return $user;
75
    }
76
}
77