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 |
||
11 | class SnsExtendedClient extends SnsClient |
||
12 | { |
||
13 | /** @var SnsClient */ |
||
14 | private $snsClient; |
||
15 | |||
16 | /** @var SnsExtendedClientConfiguration */ |
||
17 | private $configuration; |
||
18 | |||
19 | /** |
||
20 | * SnsExtendedClient constructor. |
||
21 | * @param SnsClient $snsClient |
||
22 | * @param SnsExtendedClientConfiguration $configuration |
||
23 | */ |
||
24 | 1 | public function __construct(SnsClient $snsClient, SnsExtendedClientConfiguration $configuration) |
|
29 | |||
30 | /** |
||
31 | * @param string $name |
||
32 | * @param mixed[] $args |
||
33 | * @return Result|Promise |
||
34 | * @throws ExceptionInterface |
||
35 | */ |
||
36 | 1 | public function __call($name, array $args) |
|
46 | |||
47 | /** |
||
48 | * @param mixed[] $args |
||
49 | * @return Result |
||
50 | * @throws ExceptionInterface |
||
51 | */ |
||
52 | 1 | View Code Duplication | private function publishClaimCheck(array $args = []) |
64 | |||
65 | /** |
||
66 | * @param string $message |
||
67 | * @return ClaimCheck |
||
68 | */ |
||
69 | 1 | View Code Duplication | private function storeMessageInS3($message) |
85 | } |
||
86 |
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.