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 |
||
| 31 | class LocalDriver extends DriverAbstract |
||
| 32 | { |
||
| 33 | use LocalDirTrait; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * driver root |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | * @access protected |
||
| 40 | */ |
||
| 41 | protected $root; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param string $rootDir |
||
| 45 | * @throws LogicException |
||
| 46 | * @access public |
||
| 47 | */ |
||
| 48 | public function __construct(/*# string */ $rootDir) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * {@inheritDoc} |
||
| 60 | */ |
||
| 61 | protected function realPath(/*# string */ $path)/*# : string */ |
||
| 66 | |||
| 67 | /** |
||
| 68 | * {@inheritDoc} |
||
| 69 | */ |
||
| 70 | protected function realExists(/*# string */ $realPath)/*# : bool */ |
||
| 74 | |||
| 75 | /** |
||
| 76 | * {@inheritDoc} |
||
| 77 | */ |
||
| 78 | protected function openReadStream(/*# string */ $realPath) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * {@inheritDoc} |
||
| 94 | */ |
||
| 95 | protected function readFile(/*# string */ $realPath) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * {@inheritDoc} |
||
| 112 | */ |
||
| 113 | protected function getRealMeta(/*# string */ $realPath)/*# : array */ |
||
| 131 | |||
| 132 | /** |
||
| 133 | * {@inheritDoc} |
||
| 134 | */ |
||
| 135 | protected function ensurePath(/*# string */ $realPath)/*# : bool */ |
||
| 143 | |||
| 144 | /** |
||
| 145 | * {@inheritDoc} |
||
| 146 | */ |
||
| 147 | View Code Duplication | protected function writeStream( |
|
| 163 | |||
| 164 | /** |
||
| 165 | * {@inheritDoc} |
||
| 166 | */ |
||
| 167 | View Code Duplication | protected function writeFile( |
|
| 184 | |||
| 185 | /** |
||
| 186 | * {@inheritDoc} |
||
| 187 | */ |
||
| 188 | protected function setRealMeta( |
||
| 203 | |||
| 204 | /** |
||
| 205 | * {@inheritDoc} |
||
| 206 | */ |
||
| 207 | protected function renameFile( |
||
| 213 | |||
| 214 | /** |
||
| 215 | * {@inheritDoc} |
||
| 216 | */ |
||
| 217 | protected function copyFile( |
||
| 223 | |||
| 224 | /** |
||
| 225 | * {@inheritDoc} |
||
| 226 | */ |
||
| 227 | protected function deleteFile(/*# string */ $realPath)/*# : bool */ |
||
| 231 | } |
||
| 232 |