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 |
||
25 | trait StandardPsr6StructureTrait |
||
26 | { |
||
27 | use ClassNamespaceResolverTrait; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $deferredList = []; |
||
33 | |||
34 | /** |
||
35 | * @var ExtendedCacheItemInterface[] |
||
36 | */ |
||
37 | protected $itemInstances = []; |
||
38 | |||
39 | /** |
||
40 | * @param string $key |
||
41 | * @return \phpFastCache\Cache\ExtendedCacheItemInterface |
||
42 | * @throws \InvalidArgumentException |
||
43 | */ |
||
44 | public function getItem($key) |
||
85 | |||
86 | /** |
||
87 | * @param \Psr\Cache\CacheItemInterface $item |
||
88 | * @return $this |
||
89 | * @throws \InvalidArgumentException |
||
90 | */ |
||
91 | public function setItem(CacheItemInterface $item) |
||
101 | |||
102 | /** |
||
103 | * @param array $keys |
||
104 | * @return CacheItemInterface[] |
||
105 | * @throws \InvalidArgumentException |
||
106 | */ |
||
107 | public function getItems(array $keys = []) |
||
116 | |||
117 | /** |
||
118 | * @param string $key |
||
119 | * @return bool |
||
120 | * @throws \InvalidArgumentException |
||
121 | */ |
||
122 | public function hasItem($key) |
||
128 | |||
129 | /** |
||
130 | * @return bool |
||
131 | */ |
||
132 | public function clear() |
||
139 | |||
140 | /** |
||
141 | * @param string $key |
||
142 | * @return bool |
||
143 | * @throws \InvalidArgumentException |
||
144 | */ |
||
145 | public function deleteItem($key) |
||
162 | |||
163 | /** |
||
164 | * @param array $keys |
||
165 | * @return bool |
||
166 | * @throws \InvalidArgumentException |
||
167 | */ |
||
168 | public function deleteItems(array $keys) |
||
180 | |||
181 | /** |
||
182 | * @param \Psr\Cache\CacheItemInterface $item |
||
183 | * @return mixed |
||
184 | * @throws \InvalidArgumentException |
||
185 | * @throws \RuntimeException |
||
186 | */ |
||
187 | public function save(CacheItemInterface $item) |
||
208 | |||
209 | /** |
||
210 | * @param \Psr\Cache\CacheItemInterface $item |
||
211 | * @return \Psr\Cache\CacheItemInterface |
||
212 | * @throws \RuntimeException |
||
213 | */ |
||
214 | public function saveDeferred(CacheItemInterface $item) |
||
224 | |||
225 | /** |
||
226 | * @return mixed|null |
||
227 | * @throws \InvalidArgumentException |
||
228 | */ |
||
229 | public function commit() |
||
242 | } |
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.