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 | public static function getInstance() |
||
| 37 | |||
| 38 | public function getCacheForPath($path) |
||
| 57 | |||
| 58 | public function setStoragePath($storagePath) |
||
| 62 | |||
| 63 | View Code Duplication | private function getDbInstance() |
|
| 70 | |||
| 71 | public function init($baseCacheSqlPath) |
||
| 79 | |||
| 80 | public function setCacheForPath($requestUri, $renderedContent) |
||
| 101 | |||
| 102 | } |