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) { |
||
102 | |||
103 | /** |
||
104 | * Find all mounts in $path |
||
105 | * |
||
106 | * @param string $path |
||
107 | * @return MountPoint[] |
||
108 | */ |
||
109 | public function findIn($path) { |
||
124 | |||
125 | public function clear() { |
||
129 | |||
130 | /** |
||
131 | * Find mounts by storage id |
||
132 | * |
||
133 | * @param string $id |
||
134 | * @return MountPoint[] |
||
135 | */ |
||
136 | public function findByStorageId($id) { |
||
149 | |||
150 | /** |
||
151 | * @return MountPoint[] |
||
152 | */ |
||
153 | public function getAll() { |
||
156 | |||
157 | /** |
||
158 | * Find mounts by numeric storage id |
||
159 | * |
||
160 | * @param int $id |
||
161 | * @return MountPoint[] |
||
162 | */ |
||
163 | public function findByNumericId($id) { |
||
167 | |||
168 | /** |
||
169 | * @param string $path |
||
170 | * @return string |
||
171 | */ |
||
172 | View Code Duplication | private function formatPath($path) { |
|
179 | } |
||
180 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.