WithoutOldPasswordChangeUserPasswordHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 46
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A __invoke() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the BenGorUser package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorUser\User\Application\Command\ChangePassword;
14
15
use BenGorUser\User\Domain\Model\Exception\UserDoesNotExistException;
16
use BenGorUser\User\Domain\Model\UserEmail;
17
use BenGorUser\User\Domain\Model\UserPassword;
18
use BenGorUser\User\Domain\Model\UserPasswordEncoder;
19
use BenGorUser\User\Domain\Model\UserRepository;
20
21
/**
22
 * Without old password change user password command handler class.
23
 *
24
 * @author Beñat Espiña <[email protected]>
25
 * @author Gorka Laucirica <[email protected]>
26
 */
27 View Code Duplication
class WithoutOldPasswordChangeUserPasswordHandler
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
{
29
    /**
30
     * The user password encoder.
31
     *
32
     * @var UserPasswordEncoder
33
     */
34
    private $encoder;
35
36
    /**
37
     * The user repository.
38
     *
39
     * @var UserRepository
40
     */
41
    private $repository;
42
43
    /**
44
     * Constructor.
45
     *
46
     * @param UserRepository      $aRepository The user repository
47
     * @param UserPasswordEncoder $anEncoder   The password encoder
48
     */
49
    public function __construct(UserRepository $aRepository, UserPasswordEncoder $anEncoder)
50
    {
51
        $this->repository = $aRepository;
52
        $this->encoder = $anEncoder;
53
    }
54
55
    /**
56
     * Handles the given command.
57
     *
58
     * @param WithoutOldPasswordChangeUserPasswordCommand $aCommand The command
59
     *
60
     * @throws UserDoesNotExistException when the user does not exist
61
     */
62
    public function __invoke(WithoutOldPasswordChangeUserPasswordCommand $aCommand)
63
    {
64
        $user = $this->repository->userOfEmail(new UserEmail($aCommand->email()));
65
        if (null === $user) {
66
            throw new UserDoesNotExistException();
67
        }
68
        $user->changePassword(UserPassword::fromPlain($aCommand->newPlainPassword(), $this->encoder));
69
70
        $this->repository->persist($user);
71
    }
72
}
73