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 | trait MountableTrait |
||
34 | { |
||
35 | /** |
||
36 | * filesystem map |
||
37 | * |
||
38 | * @var FilesystemInterface[] |
||
39 | * @access protected |
||
40 | */ |
||
41 | protected $filesystems = []; |
||
42 | |||
43 | /** |
||
44 | * {@inheritDoc} |
||
45 | */ |
||
46 | View Code Duplication | public function mount( |
|
64 | |||
65 | /** |
||
66 | * {@inheritDoc} |
||
67 | */ |
||
68 | View Code Duplication | public function umount(/*# string */ $mountPoint)/*# : bool */ |
|
86 | |||
87 | /** |
||
88 | * Clean path to standard mount point |
||
89 | * |
||
90 | * @param string $path |
||
91 | * @return string |
||
92 | * @access protected |
||
93 | */ |
||
94 | protected function cleanMountPoint(/*# string */ $path)/*# : string */ |
||
98 | |||
99 | /** |
||
100 | * Get the filesystem at mount point |
||
101 | * |
||
102 | * @param string $mountPoint |
||
103 | * @return FilesystemInterface |
||
104 | * @access protected |
||
105 | */ |
||
106 | protected function getFilesystemAt( |
||
111 | |||
112 | /** |
||
113 | * Find mount point of the path |
||
114 | * |
||
115 | * @param string $path |
||
116 | * @return string |
||
117 | * @access protected |
||
118 | */ |
||
119 | protected function getMountPoint(/*# string */ $path)/*# : string */ |
||
129 | } |
||
130 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.