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

ChangePasswordHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A success() 0 14 3
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Form\Handler;
4
5
use Silverback\ApiComponentBundle\Entity\User\User;
6
use App\Exception\NotSupportedException;
0 ignored issues
show
Bug introduced by
The type App\Exception\NotSupportedException 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 App\Security\PasswordManager;
0 ignored issues
show
Bug introduced by
The type App\Security\PasswordManager 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 Silverback\ApiComponentBundle\Entity\Component\Form\Form;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class ChangePasswordHandler implements FormHandlerInterface
12
{
13
    private $passwordManager;
14
15
    public function __construct(
16
        PasswordManager $passwordManager
17
    ) {
18
        $this->passwordManager = $passwordManager;
19
    }
20
21
    /**
22
     * @param Form $form
23
     * @param User $user
24
     * @param Request $request
25
     * @throws NotSupportedException
26
     */
27
    public function success(Form $form, $user, Request $request): void
28
    {
29
        if (!$user instanceof User) {
0 ignored issues
show
introduced by
$user is always a sub-type of Silverback\ApiComponentBundle\Entity\User\User.
Loading history...
30
            throw new NotSupportedException(
31
                sprintf(
32
                    '`%s` only supports forms that submit the `%s` entity. Received `%s`',
33
                    self::class,
34
                    User::class,
35
                    \is_object($user) ? \get_class($user) : $user
36
                )
37
            );
38
        }
39
        $this->passwordManager->persistPlainPassword($user);
40
        $user->eraseCredentials();
41
    }
42
}
43