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 |
||
31 | class Driver extends DriverAbstract |
||
32 | { |
||
33 | use PathSeekerTrait, StandardPsr6StructureTrait; |
||
34 | /** |
||
35 | * |
||
36 | */ |
||
37 | const FILE_DIR = 'files'; |
||
38 | |||
39 | /** |
||
40 | * Driver constructor. |
||
41 | * @param array $config |
||
42 | * @throws phpFastCacheDriverException |
||
43 | */ |
||
44 | public function __construct(array $config = []) |
||
52 | |||
53 | /** |
||
54 | * @return bool |
||
55 | */ |
||
56 | public function driverCheck() |
||
60 | |||
61 | /** |
||
62 | * @param \Psr\Cache\CacheItemInterface $item |
||
63 | * @return mixed |
||
64 | * @throws \InvalidArgumentException |
||
65 | */ |
||
66 | public function driverWrite(CacheItemInterface $item) |
||
104 | |||
105 | /** |
||
106 | * @param string $key |
||
107 | * @return mixed |
||
108 | * @throws \InvalidArgumentException |
||
109 | */ |
||
110 | public function driverRead($key) |
||
132 | |||
133 | /** |
||
134 | * @param \Psr\Cache\CacheItemInterface $item |
||
135 | * @return bool |
||
136 | * @throws \InvalidArgumentException |
||
137 | */ |
||
138 | public function driverDelete(CacheItemInterface $item) |
||
154 | |||
155 | /** |
||
156 | * @return bool |
||
157 | */ |
||
158 | public function driverClear() |
||
162 | |||
163 | /** |
||
164 | * @return bool |
||
165 | */ |
||
166 | public function driverConnect() |
||
170 | |||
171 | /** |
||
172 | * @param \Psr\Cache\CacheItemInterface $item |
||
173 | * @return bool |
||
174 | * @throws \InvalidArgumentException |
||
175 | */ |
||
176 | public function driverIsHit(CacheItemInterface $item) |
||
188 | |||
189 | /** |
||
190 | * @param string $optionName |
||
191 | * @param mixed $optionValue |
||
192 | * @return bool |
||
193 | * @throws \InvalidArgumentException |
||
194 | */ |
||
195 | public static function isValidOption($optionName, $optionValue) |
||
219 | |||
220 | /** |
||
221 | * @return array |
||
222 | */ |
||
223 | public static function getValidOptions() |
||
227 | |||
228 | /** |
||
229 | * @return array |
||
230 | */ |
||
231 | public static function getRequiredOptions() |
||
235 | |||
236 | /******************** |
||
237 | * |
||
238 | * PSR-6 Extended Methods |
||
239 | * |
||
240 | *******************/ |
||
241 | |||
242 | /** |
||
243 | * @return driverStatistic |
||
244 | * @throws \phpFastCache\Exceptions\phpFastCacheCoreException |
||
245 | * @throws \phpFastCache\Exceptions\phpFastCacheDriverException |
||
246 | */ |
||
247 | View Code Duplication | public function getStats() |
|
263 | } |
$this->getFileDir()
can contain request data and is used in file manipulation context(s) leading to a potential security vulnerability.General Strategies to prevent injection
In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:
For numeric data, we recommend to explicitly cast the data: