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( |
|
| 162 | |||
| 163 | /** |
||
| 164 | * {@inheritDoc} |
||
| 165 | */ |
||
| 166 | View Code Duplication | protected function writeFile( |
|
| 181 | |||
| 182 | /** |
||
| 183 | * {@inheritDoc} |
||
| 184 | */ |
||
| 185 | protected function setRealMeta( |
||
| 200 | |||
| 201 | /** |
||
| 202 | * {@inheritDoc} |
||
| 203 | */ |
||
| 204 | protected function renameFile( |
||
| 210 | |||
| 211 | /** |
||
| 212 | * {@inheritDoc} |
||
| 213 | */ |
||
| 214 | protected function copyFile( |
||
| 220 | |||
| 221 | /** |
||
| 222 | * {@inheritDoc} |
||
| 223 | */ |
||
| 224 | protected function deleteFile(/*# string */ $realPath)/*# : bool */ |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Rename tmpfile |
||
| 231 | * |
||
| 232 | * @param string $tmpFile |
||
| 233 | * @param string $realPath |
||
| 234 | * @return bool |
||
| 235 | * @access protected |
||
| 236 | */ |
||
| 237 | protected function renameTempFile( |
||
| 250 | } |
||
| 251 |
If you suppress an error, we recommend checking for the error condition explicitly: