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 |
||
28 | View Code Duplication | class Driver implements ExtendedCacheItemPoolInterface |
|
1 ignored issue
–
show
|
|||
29 | { |
||
30 | use DriverBaseTrait; |
||
31 | |||
32 | /** |
||
33 | * Driver constructor. |
||
34 | * @param array $config |
||
35 | * @throws phpFastCacheDriverException |
||
36 | */ |
||
37 | public function __construct(array $config = []) |
||
45 | |||
46 | /** |
||
47 | * @return bool |
||
48 | */ |
||
49 | public function driverCheck() |
||
53 | |||
54 | /** |
||
55 | * @param \Psr\Cache\CacheItemInterface $item |
||
56 | * @return mixed |
||
57 | * @throws \InvalidArgumentException |
||
58 | */ |
||
59 | protected function driverWrite(CacheItemInterface $item) |
||
70 | |||
71 | /** |
||
72 | * @param \Psr\Cache\CacheItemInterface $item |
||
73 | * @return array [ |
||
74 | * 'd' => 'THE ITEM DATA' |
||
75 | * 't' => 'THE ITEM DATE EXPIRATION' |
||
76 | * 'g' => 'THE ITEM TAGS' |
||
77 | * ] |
||
78 | */ |
||
79 | protected function driverRead(CacheItemInterface $item) |
||
87 | /** |
||
88 | * @param \Psr\Cache\CacheItemInterface $item |
||
89 | * @return bool |
||
90 | * @throws \InvalidArgumentException |
||
91 | */ |
||
92 | protected function driverDelete(CacheItemInterface $item) |
||
103 | |||
104 | /** |
||
105 | * @return bool |
||
106 | */ |
||
107 | protected function driverClear() |
||
111 | |||
112 | /** |
||
113 | * @return bool |
||
114 | */ |
||
115 | protected function driverConnect() |
||
119 | |||
120 | /******************** |
||
121 | * |
||
122 | * PSR-6 Extended Methods |
||
123 | * |
||
124 | *******************/ |
||
125 | |||
126 | /** |
||
127 | * @return driverStatistic |
||
128 | */ |
||
129 | public function getStats() |
||
139 | } |
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.