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 |
||
19 | View Code Duplication | class PhpRedisLock extends LockAbstract |
|
|
|||
20 | { |
||
21 | /** |
||
22 | * phpredis connection |
||
23 | * |
||
24 | * @var |
||
25 | */ |
||
26 | protected $client; |
||
27 | |||
28 | /** |
||
29 | * @param $client Redis |
||
30 | */ |
||
31 | public function __construct(Redis $client) |
||
37 | |||
38 | /** |
||
39 | * @param string $name |
||
40 | * @param bool $blocking |
||
41 | * @return bool |
||
42 | */ |
||
43 | protected function getLock($name, $blocking) |
||
51 | |||
52 | /** |
||
53 | * Release lock |
||
54 | * |
||
55 | * @param string $name name of lock |
||
56 | * @return bool |
||
57 | */ |
||
58 | public function releaseLock($name) |
||
68 | |||
69 | /** |
||
70 | * Check if lock is locked |
||
71 | * |
||
72 | * @param string $name name of lock |
||
73 | * @return bool |
||
74 | */ |
||
75 | public function isLocked($name) |
||
79 | } |
||
80 |
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.