Code Duplication    Length = 27-28 lines in 2 locations

Command/CreateUserHandler.php 1 location

@@ 7-33 (lines=27) @@
4
5
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection;
6
7
final class CreateUserHandler extends UserHandler
8
{
9
    /**
10
     * @var UserRepositoryCollection
11
     */
12
    private $userRepositoryCollection;
13
14
    /**
15
     * CreateUserHandler constructor.
16
     *
17
     * @param UserRepositoryCollection $userRepositoryCollection
18
     */
19
    public function __construct(UserRepositoryCollection $userRepositoryCollection)
20
    {
21
        $this->userRepositoryCollection = $userRepositoryCollection;
22
    }
23
24
    /**
25
     * @param CreateUser $command
26
     */
27
    public function handle(CreateUser $command, $class)
28
    {
29
        $user = new $class(
30
            $command->getUsername(),
31
            $command->getPassword(),
32
            $command->getDisplayName()
33
        );
34
        $repository = $this->getUserRepositoryForUser($this->userRepositoryCollection, $user);
35
        $repository->add($user);
36
    }

Command/UpdateUserHandler.php 1 location

@@ 8-35 (lines=28) @@
5
use SumoCoders\FrameworkMultiUserBundle\User\User;
6
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection;
7
8
final class UpdateUserHandler extends UserHandler
9
{
10
    /**
11
     * @var UserRepositoryCollection
12
     */
13
    private $userRepositoryCollection;
14
15
    /**
16
     * CreateUserHandler constructor.
17
     *
18
     * @param UserRepositoryCollection $userRepositoryCollection
19
     */
20
    public function __construct(UserRepositoryCollection $userRepositoryCollection)
21
    {
22
        $this->userRepositoryCollection = $userRepositoryCollection;
23
    }
24
25
    /**
26
     * @param UpdateUser $command
27
     */
28
    public function handle(UpdateUser $command)
29
    {
30
        $updatingUser = $command->getUser();
31
        $user = new User(
32
            $command->getUsername(),
33
            $command->getPassword(),
34
            $command->getDisplayName()
35
        );
36
        $repository = $this->getUserRepositoryForUser($this->userRepositoryCollection, $updatingUser);
37
        $repository->update($updatingUser, $user);
38
    }