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 |
||
| 11 | class Cache |
||
|
|
|||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var Cache |
||
| 15 | */ |
||
| 16 | private static $instance; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $storagePath; |
||
| 22 | /** |
||
| 23 | * @var \PDO |
||
| 24 | */ |
||
| 25 | protected $dbHandle; |
||
| 26 | |||
| 27 | private function __construct() |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @return Cache |
||
| 34 | */ |
||
| 35 | public static function getInstance() |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param $path |
||
| 45 | * @return \stdClass |
||
| 46 | */ |
||
| 47 | public function getCacheForPath($path) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Clears all cache |
||
| 69 | */ |
||
| 70 | public function clearCache() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @param $storagePath |
||
| 89 | */ |
||
| 90 | public function setStoragePath($storagePath) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @return \PDO |
||
| 97 | */ |
||
| 98 | View Code Duplication | private function getDbInstance() |
|
| 105 | |||
| 106 | /** |
||
| 107 | * @param $baseCacheSqlPath |
||
| 108 | */ |
||
| 109 | public function init($baseCacheSqlPath) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @param $requestUri |
||
| 120 | * @param $renderedContent |
||
| 121 | */ |
||
| 122 | public function setCacheForPath($requestUri, $renderedContent) |
||
| 147 | |||
| 148 | } |