Complex classes like LocalDriver often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use LocalDriver, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class LocalDriver extends DriverAbstract |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * driver root |
||
| 33 | * |
||
| 34 | * @var string |
||
| 35 | * @access protected |
||
| 36 | */ |
||
| 37 | protected $root; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param string $rootDir |
||
| 41 | * @throws LogicException |
||
| 42 | * @access public |
||
| 43 | */ |
||
| 44 | public function __construct(/*# string */ $rootDir) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritDoc} |
||
| 56 | */ |
||
| 57 | protected function realPath(/*# string */ $path)/*# : string */ |
||
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritDoc} |
||
| 64 | */ |
||
| 65 | protected function realExists(/*# string */ $realPath)/*# : bool */ |
||
| 69 | |||
| 70 | /** |
||
| 71 | * {@inheritDoc} |
||
| 72 | */ |
||
| 73 | protected function isDir(/*# string */ $realPath)/*# : bool */ |
||
| 77 | |||
| 78 | /** |
||
| 79 | * {@inheritDoc} |
||
| 80 | */ |
||
| 81 | protected function readDir( |
||
| 101 | |||
| 102 | /** |
||
| 103 | * {@inheritDoc} |
||
| 104 | */ |
||
| 105 | protected function openReadStream(/*# string */ $realPath) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * {@inheritDoc} |
||
| 121 | */ |
||
| 122 | protected function readFile(/*# string */ $realPath) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * {@inheritDoc} |
||
| 139 | */ |
||
| 140 | protected function getRealMeta(/*# string */ $realPath)/*# : array */ |
||
| 159 | |||
| 160 | /** |
||
| 161 | * {@inheritDoc} |
||
| 162 | */ |
||
| 163 | protected function fixPath()/*# : bool */ |
||
| 173 | |||
| 174 | /** |
||
| 175 | * {@inheritDoc} |
||
| 176 | */ |
||
| 177 | protected function writeStream( |
||
| 190 | |||
| 191 | /** |
||
| 192 | * {@inheritDoc} |
||
| 193 | */ |
||
| 194 | protected function writeFile( |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Write meta data |
||
| 210 | * |
||
| 211 | * @param string $realPath |
||
| 212 | * @param array $meta |
||
| 213 | * @return bool |
||
| 214 | * @access protected |
||
| 215 | */ |
||
| 216 | protected function setRealMeta( |
||
| 229 | |||
| 230 | /** |
||
| 231 | * {@inheritDoc} |
||
| 232 | */ |
||
| 233 | protected function renameDir( |
||
| 239 | |||
| 240 | /** |
||
| 241 | * {@inheritDoc} |
||
| 242 | */ |
||
| 243 | protected function renameFile( |
||
| 249 | |||
| 250 | /** |
||
| 251 | * {@inheritDoc} |
||
| 252 | */ |
||
| 253 | protected function copyDir( |
||
| 274 | |||
| 275 | /** |
||
| 276 | * {@inheritDoc} |
||
| 277 | */ |
||
| 278 | protected function copyFile( |
||
| 284 | |||
| 285 | /** |
||
| 286 | * {@inheritDoc} |
||
| 287 | */ |
||
| 288 | protected function deleteDir(/*# string */ $realPath)/*# : bool */ |
||
| 307 | |||
| 308 | /** |
||
| 309 | * {@inheritDoc} |
||
| 310 | */ |
||
| 311 | protected function deleteFile(/*# string */ $realPath)/*# : bool */ |
||
| 315 | |||
| 316 | /** |
||
| 317 | * create directory |
||
| 318 | * |
||
| 319 | * @param string $dir |
||
| 320 | * @access protected |
||
| 321 | */ |
||
| 322 | protected function makeDirectory(/*# string */ $dir)/*# : bool */ |
||
| 339 | } |
||
| 340 |