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 |
||
13 | View Code Duplication | class Locator extends Service implements SearchService, NotificationService |
|
|
|||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | const ENDPOINT = '/v2/pre-approvals'; |
||
19 | |||
20 | /** |
||
21 | * @var Decoder |
||
22 | */ |
||
23 | private $decoder; |
||
24 | |||
25 | /** |
||
26 | * @param Credentials $credentials |
||
27 | * @param Client $client |
||
28 | * @param Decoder $decoder |
||
29 | */ |
||
30 | 3 | public function __construct( |
|
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | 1 | public function getByCode($code) |
|
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 1 | public function getByNotification($code) |
|
55 | } |
||
56 |
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.