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  | 
            ||
| 9 | class Cache  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 10 | { | 
            ||
| 11 | /**  | 
            ||
| 12 | * @var Cache  | 
            ||
| 13 | */  | 
            ||
| 14 | private static $instance;  | 
            ||
| 15 | |||
| 16 | /**  | 
            ||
| 17 | * @var string  | 
            ||
| 18 | */  | 
            ||
| 19 | protected $storagePath;  | 
            ||
| 20 | /**  | 
            ||
| 21 | * @var \PDO  | 
            ||
| 22 | */  | 
            ||
| 23 | protected $dbHandle;  | 
            ||
| 24 | |||
| 25 | private function __construct()  | 
            ||
| 29 | |||
| 30 | /**  | 
            ||
| 31 | * @return Cache  | 
            ||
| 32 | */  | 
            ||
| 33 | public static function getInstance()  | 
            ||
| 40 | |||
| 41 | /**  | 
            ||
| 42 | * @param $path  | 
            ||
| 43 | * @return \stdClass  | 
            ||
| 44 | */  | 
            ||
| 45 | public function getCacheForPath($path)  | 
            ||
| 64 | |||
| 65 | /**  | 
            ||
| 66 | * Clears all cache  | 
            ||
| 67 | */  | 
            ||
| 68 | public function clearCache()  | 
            ||
| 84 | |||
| 85 | /**  | 
            ||
| 86 | * @param $storagePath  | 
            ||
| 87 | */  | 
            ||
| 88 | public function setStoragePath($storagePath)  | 
            ||
| 92 | |||
| 93 | /**  | 
            ||
| 94 | * @return \PDO  | 
            ||
| 95 | */  | 
            ||
| 96 | View Code Duplication | private function getDbInstance()  | 
            |
| 103 | |||
| 104 | /**  | 
            ||
| 105 | * @param $baseCacheSqlPath  | 
            ||
| 106 | */  | 
            ||
| 107 | public function init($baseCacheSqlPath)  | 
            ||
| 115 | |||
| 116 | /**  | 
            ||
| 117 | * @param $requestUri  | 
            ||
| 118 | * @param $renderedContent  | 
            ||
| 119 | */  | 
            ||
| 120 | public function setCacheForPath($requestUri, $renderedContent)  | 
            ||
| 141 | |||
| 142 | }  |