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 |
||
15 | class RedisWriteReadDeleteCheck extends AbstractRedisCheck |
||
16 | { |
||
17 | const CHECK = 'redis-write-read-delete-check'; |
||
18 | |||
19 | /** |
||
20 | * @var PredisClient |
||
21 | */ |
||
22 | protected $client; |
||
23 | |||
24 | /** |
||
25 | * @param string $checkNode |
||
26 | * @param PredisClient $client |
||
27 | */ |
||
28 | 6 | public function __construct($checkNode, PredisClient $client) |
|
33 | |||
34 | /** |
||
35 | * Test redis write&read&delete. |
||
36 | * |
||
37 | * @throws RedisDeleteCheckException |
||
38 | * @throws RedisWRDCheckException |
||
39 | * @throws RedisWriteReadCheckException |
||
40 | */ |
||
41 | 6 | public function performCheck() |
|
72 | |||
73 | /** |
||
74 | * @return PredisClient |
||
75 | */ |
||
76 | 6 | public function getClient() |
|
80 | |||
81 | /** |
||
82 | * @param PredisClient $client |
||
83 | */ |
||
84 | 6 | protected function setClient(PredisClient $client) |
|
88 | } |
||
89 |
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.