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 |
||
20 | View Code Duplication | abstract class AbstractCommand |
|
|
|||
21 | { |
||
22 | use PopulatePropertiesTrait; |
||
23 | |||
24 | /** |
||
25 | * List of aggregate root impacted by this command. |
||
26 | * This should be set by the CommandHandler when it get all the aggregate roots according to the command's data. |
||
27 | * You'll probably manage only one aggregate root per command. It's an array just in case you need more. |
||
28 | * |
||
29 | * See CommandHandler for more details on the purpose of this. |
||
30 | * |
||
31 | * @var AbstractAggregateRoot[] |
||
32 | */ |
||
33 | public $aggregateRoots = []; |
||
34 | |||
35 | /** |
||
36 | * The command requester. |
||
37 | * We use the same object type (Author) as for an event in order to keep the track of the Command Requester |
||
38 | * in the Event ($author). |
||
39 | * |
||
40 | * @var Author |
||
41 | */ |
||
42 | public $requester; |
||
43 | |||
44 | /** |
||
45 | * @param array $data An array ['propertyName' => 'value', ...] |
||
46 | */ |
||
47 | public function __construct(array $data = []) |
||
52 | |||
53 | /** |
||
54 | * @param AbstractAggregateRoot $abstractAggregateRoot |
||
55 | */ |
||
56 | public function addAggregateRoot(AbstractAggregateRoot $abstractAggregateRoot) |
||
60 | } |
||
61 |
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.