Test Failed
Push — develop ( 28e0cd...307ddb )
by Daniel
05:05
created

NewUsernameHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Form\Handler;
4
5
use Silverback\ApiComponentBundle\Entity\User\User;
6
use App\Security\TokenGenerator;
0 ignored issues
show
Bug introduced by
The type App\Security\TokenGenerator 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 Doctrine\ORM\EntityManagerInterface;
8
use Silverback\ApiComponentBundle\Entity\Component\Form\Form;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class NewUsernameHandler implements FormHandlerInterface, ContextProviderInterface
12
{
13
    private $entityManager;
14
    private $tokenGenerator;
15
16
    public function __construct(
17
        EntityManagerInterface $entityManager,
18
        TokenGenerator $tokenGenerator
19
    ) {
20
        $this->entityManager = $entityManager;
21
        $this->tokenGenerator = $tokenGenerator;
22
    }
23
24
    /**
25
     * @param Form $form
26
     * @param User $data
27
     * @param Request $request
28
     * @return User
29
     */
30
    public function success(Form $form, $data, Request $request): User
31
    {
32
        // send an email to the new email address with the confirmation token to validate the new email
33
        $data->setUsernameConfirmationToken($this->tokenGenerator->generateToken());
34
        $this->entityManager->persist($data);
35
        $this->entityManager->flush();
36
        return $data;
37
    }
38
39
    public function getContext(): ?array
40
    {
41
        return ['groups' => ['new_username']];
42
    }
43
}
44