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 |
||
| 33 | class Manager implements IMountManager { |
||
| 34 | /** @var MountPoint[] */ |
||
| 35 | private $mounts = []; |
||
| 36 | |||
| 37 | /** @var CappedMemoryCache */ |
||
| 38 | private $inPathCache; |
||
| 39 | |||
| 40 | public function __construct() { |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param IMountPoint $mount |
||
| 46 | */ |
||
| 47 | public function addMount(IMountPoint $mount) { |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param string $mountPoint |
||
| 54 | */ |
||
| 55 | public function removeMount($mountPoint) { |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param string $mountPoint |
||
| 66 | * @param string $target |
||
| 67 | */ |
||
| 68 | public function moveMount($mountPoint, $target) { |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Find the mount for $path |
||
| 76 | * |
||
| 77 | * @param string $path |
||
| 78 | * @return MountPoint |
||
| 79 | */ |
||
| 80 | public function find($path) { |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Find all mounts in $path |
||
| 104 | * |
||
| 105 | * @param string $path |
||
| 106 | * @return MountPoint[] |
||
| 107 | */ |
||
| 108 | public function findIn($path) { |
||
| 128 | |||
| 129 | public function clear() { |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Find mounts by storage id |
||
| 136 | * |
||
| 137 | * @param string $id |
||
| 138 | * @return MountPoint[] |
||
| 139 | */ |
||
| 140 | public function findByStorageId($id) { |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @return MountPoint[] |
||
| 156 | */ |
||
| 157 | public function getAll() { |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Find mounts by numeric storage id |
||
| 163 | * |
||
| 164 | * @param int $id |
||
| 165 | * @return MountPoint[] |
||
| 166 | */ |
||
| 167 | public function findByNumericId($id) { |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @param string $path |
||
| 174 | * @return string |
||
| 175 | */ |
||
| 176 | View Code Duplication | private function formatPath($path) { |
|
| 183 | } |
||
| 184 |