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 namespace RayEmitter\Example\BankAccount; |
||
6 | final class Aggregate extends AbstractAggregate |
||
7 | { |
||
8 | /** |
||
9 | * Minimum needed to open an account. |
||
10 | * @var int|float |
||
11 | */ |
||
12 | const MINIMUM_TO_OPEN = 50; |
||
13 | |||
14 | /** |
||
15 | * Account Was Created Event Handle |
||
16 | * |
||
17 | * @param AccountWasCreated $event Event Object |
||
18 | * @return void |
||
19 | */ |
||
20 | protected function applyAccountWasCreated(AccountWasCreated $event) |
||
28 | |||
29 | /** |
||
30 | * Money Deposited Event Handle |
||
31 | * |
||
32 | * @param MoneyDeposited $event Event Object |
||
33 | * @return void |
||
34 | */ |
||
35 | View Code Duplication | protected function applyMoneyDeposited(MoneyDeposited $event) |
|
42 | |||
43 | /** |
||
44 | * Money Withdrawn Event Handle |
||
45 | * |
||
46 | * @param MoneyWithdrawn $event Event Object |
||
47 | * @return void |
||
48 | */ |
||
49 | View Code Duplication | protected function applyMoneyWithdrawn(MoneyWithdrawn $event) |
|
56 | |||
57 | /** |
||
58 | * Create Account Command Handle |
||
59 | * |
||
60 | * Processes business logic for the account creation command. |
||
61 | * @param CreateAccount $command Command object. |
||
62 | * @return AccountWasCreated Event object. |
||
63 | */ |
||
64 | protected function handleCreateAccount(CreateAccount $command) |
||
82 | |||
83 | /** |
||
84 | * Deposit Money Command Handle |
||
85 | * |
||
86 | * Processes business logic for the deposit money command. |
||
87 | * @param DepositMoney $command Command object. |
||
88 | * @return MoneyDeposited Event object. |
||
89 | */ |
||
90 | protected function handleDepositMoney(DepositMoney $command) |
||
101 | |||
102 | /** |
||
103 | * Withdraw Money Command Handle |
||
104 | * |
||
105 | * Processes business logic for the withdraw money command. |
||
106 | * @param WithdrawMoney $command Command object. |
||
107 | * @return MoneyWithdrawn Event object. |
||
108 | */ |
||
109 | protected function handleWithdrawMoney(WithdrawMoney $command) |
||
128 | } |
||
129 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..