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 |
||
| 7 | class FileCache implements CacheInterface |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | private $dir; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * FileCache constructor. |
||
| 16 | * |
||
| 17 | * @param string $dir |
||
| 18 | */ |
||
| 19 | public function __construct($dir) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritDoc} |
||
| 30 | */ |
||
| 31 | View Code Duplication | public function loadClassMetadataFromCache(\ReflectionClass $class) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * {@inheritDoc} |
||
| 43 | */ |
||
| 44 | public function putClassMetadataInCache(ClassMetadata $metadata) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritDoc} |
||
| 64 | */ |
||
| 65 | View Code Duplication | public function evictClassMetadataFromCache(\ReflectionClass $class) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * @param ClassMetadata $metadata |
||
| 75 | * |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | private function getFileName(ClassMetadata $metadata) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @param $dir |
||
| 85 | */ |
||
| 86 | private function createDirectory($dir) |
||
| 92 | } |
||
| 93 |