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 */ |
||
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritDoc} |
||
| 65 | */ |
||
| 66 | protected function realExists(/*# string */ $realPath)/*# : bool */ |
||
| 70 | |||
| 71 | /** |
||
| 72 | * {@inheritDoc} |
||
| 73 | */ |
||
| 74 | protected function isDir(/*# string */ $realPath)/*# : bool */ |
||
| 78 | |||
| 79 | /** |
||
| 80 | * {@inheritDoc} |
||
| 81 | */ |
||
| 82 | protected function readDir( |
||
| 102 | |||
| 103 | /** |
||
| 104 | * {@inheritDoc} |
||
| 105 | */ |
||
| 106 | protected function openReadStream(/*# string */ $realPath) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * {@inheritDoc} |
||
| 122 | */ |
||
| 123 | protected function readFile(/*# string */ $realPath) |
||
| 137 | |||
| 138 | /** |
||
| 139 | * {@inheritDoc} |
||
| 140 | */ |
||
| 141 | protected function getRealMeta(/*# string */ $realPath)/*# : array */ |
||
| 159 | |||
| 160 | /** |
||
| 161 | * {@inheritDoc} |
||
| 162 | */ |
||
| 163 | protected function ensurePath(/*# string */ $realPath)/*# : bool */ |
||
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritDoc} |
||
| 174 | */ |
||
| 175 | protected function writeStream( |
||
| 188 | |||
| 189 | /** |
||
| 190 | * {@inheritDoc} |
||
| 191 | */ |
||
| 192 | protected function writeFile( |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Write meta data |
||
| 208 | * |
||
| 209 | * @param string $realPath |
||
| 210 | * @param array $meta |
||
| 211 | * @return bool |
||
| 212 | * @access protected |
||
| 213 | */ |
||
| 214 | protected function setRealMeta( |
||
| 227 | |||
| 228 | /** |
||
| 229 | * {@inheritDoc} |
||
| 230 | */ |
||
| 231 | protected function renameDir( |
||
| 237 | |||
| 238 | /** |
||
| 239 | * {@inheritDoc} |
||
| 240 | */ |
||
| 241 | protected function renameFile( |
||
| 247 | |||
| 248 | /** |
||
| 249 | * {@inheritDoc} |
||
| 250 | */ |
||
| 251 | protected function copyDir( |
||
| 272 | |||
| 273 | /** |
||
| 274 | * {@inheritDoc} |
||
| 275 | */ |
||
| 276 | protected function copyFile( |
||
| 282 | |||
| 283 | /** |
||
| 284 | * {@inheritDoc} |
||
| 285 | */ |
||
| 286 | protected function deleteDir(/*# string */ $realPath)/*# : bool */ |
||
| 305 | |||
| 306 | /** |
||
| 307 | * {@inheritDoc} |
||
| 308 | */ |
||
| 309 | protected function deleteFile(/*# string */ $realPath)/*# : bool */ |
||
| 313 | |||
| 314 | /** |
||
| 315 | * create directory |
||
| 316 | * |
||
| 317 | * @param string $dir |
||
| 318 | * @access protected |
||
| 319 | */ |
||
| 320 | protected function makeDirectory(/*# string */ $dir)/*# : bool */ |
||
| 337 | } |
||
| 338 |