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 C4tech\RayEmitter\Example\BankAccount; |
||
| 5 | final class Aggregate extends AbstractAggregate |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Minimum needed to open an account. |
||
| 9 | * @var int|float |
||
| 10 | */ |
||
| 11 | const MINIMUM_TO_OPEN = 50; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Account Was Created Event Handle |
||
| 15 | * |
||
| 16 | * @param AccountWasCreated $event Event Object |
||
| 17 | * @return void |
||
| 18 | */ |
||
| 19 | protected function applyAccountWasCreated(AccountWasCreated $event) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Money Deposited Event Handle |
||
| 30 | * |
||
| 31 | * @param MoneyDeposited $event Event Object |
||
| 32 | * @return void |
||
| 33 | */ |
||
| 34 | View Code Duplication | protected function applyMoneyDeposited(MoneyDeposited $event) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * Money Withdrawn Event Handle |
||
| 44 | * |
||
| 45 | * @param MoneyWithdrawn $event Event Object |
||
| 46 | * @return void |
||
| 47 | */ |
||
| 48 | View Code Duplication | protected function applyMoneyWithdrawn(MoneyWithdrawn $event) |
|
| 55 | |||
| 56 | /** |
||
| 57 | * Create Account Command Handle |
||
| 58 | * |
||
| 59 | * Processes business logic for the account creation command. |
||
| 60 | * @param CreateAccount $command Command object. |
||
| 61 | * @return AccountWasCreated Event object. |
||
| 62 | */ |
||
| 63 | protected function handleCreateAccount(CreateAccount $command) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Deposit Money Command Handle |
||
| 80 | * |
||
| 81 | * Processes business logic for the deposit money command. |
||
| 82 | * @param DepositMoney $command Command object. |
||
| 83 | * @return MoneyDeposited Event object. |
||
| 84 | */ |
||
| 85 | protected function handleDepositMoney(DepositMoney $command) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Withdraw Money Command Handle |
||
| 101 | * |
||
| 102 | * Processes business logic for the withdraw money command. |
||
| 103 | * @param WithdrawMoney $command Command object. |
||
| 104 | * @return MoneyWithdrawn Event object. |
||
| 105 | */ |
||
| 106 | protected function handleWithdrawMoney(WithdrawMoney $command) |
||
| 123 | } |
||
| 124 |
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..