Completed
Push — master ( 1780f7...c63020 )
by Beñat
04:00
created

UserOfIdHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 5
dl 49
loc 49
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A __invoke() 11 11 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\Query;
14
15
use BenGorUser\User\Application\DataTransformer\UserDataTransformer;
16
use BenGorUser\User\Domain\Model\Exception\UserDoesNotExistException;
17
use BenGorUser\User\Domain\Model\UserId;
18
use BenGorUser\User\Domain\Model\UserRepository;
19
20
/**
21
 * User of id query handler.
22
 *
23
 * @author Beñat Espiña <[email protected]>
24
 */
25 View Code Duplication
class UserOfIdHandler
1 ignored issue
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...
26
{
27
    /**
28
     * The user data transformer.
29
     *
30
     * @var UserDataTransformer
31
     */
32
    private $dataTransformer;
33
34
    /**
35
     * The user repository.
36
     *
37
     * @var UserRepository
38
     */
39
    private $repository;
40
41
    /**
42
     * Constructor.
43
     *
44
     * @param UserRepository      $aRepository      The user repository
45
     * @param UserDataTransformer $aDataTransformer The user data transformer
46
     */
47
    public function __construct(UserRepository $aRepository, UserDataTransformer $aDataTransformer)
48
    {
49
        $this->repository = $aRepository;
50
        $this->dataTransformer = $aDataTransformer;
51
    }
52
53
    /**
54
     * Handles the given query.
55
     *
56
     * @param UserOfIdQuery $aQuery The query
57
     *
58
     * @throws UserDoesNotExistException when the user does not exist
59
     *
60
     * @return mixed
61
     */
62
    public function __invoke(UserOfIdQuery $aQuery)
63
    {
64
        $user = $this->repository->userOfId(new UserId($aQuery->id()));
65
        if (null === $user) {
66
            throw new UserDoesNotExistException();
67
        }
68
69
        $this->dataTransformer->write($user);
70
71
        return $this->dataTransformer->read();
72
    }
73
}
74