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 |
||
9 | class PaymentManager extends Manager |
||
10 | { |
||
11 | /** |
||
12 | * @var PaymentLineManager |
||
13 | */ |
||
14 | protected $paymentLineManager; |
||
15 | |||
16 | /** |
||
17 | * This will transform a PaymentRequest (parent) to a Payment (child). |
||
18 | * |
||
19 | * @param PaymentRequest $paymentRequest |
||
20 | * |
||
21 | * @return Payment |
||
22 | */ |
||
23 | public function createPaymentFromDandomainPaymentRequest(PaymentRequest $paymentRequest) |
||
58 | |||
59 | /** |
||
60 | * @param $id |
||
61 | * @return null|Payment |
||
62 | */ |
||
63 | public function findByOrderIdOrAltapayId($id) |
||
79 | |||
80 | /** |
||
81 | * @return Payment |
||
82 | */ |
||
83 | public function create() |
||
87 | |||
88 | /** |
||
89 | * @param Payment $obj |
||
90 | */ |
||
91 | public function delete($obj) |
||
95 | |||
96 | /** |
||
97 | * @param Payment $obj |
||
98 | * @param bool $flush |
||
99 | */ |
||
100 | public function update($obj, $flush = true) |
||
104 | |||
105 | /** |
||
106 | * @param PaymentLineManager $paymentLineManager |
||
107 | */ |
||
108 | public function setPaymentLineManager(PaymentLineManager $paymentLineManager) |
||
112 | } |
||
113 |
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.