Complex classes like FileBackendDBRepoWrapper 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 FileBackendDBRepoWrapper, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 40 | class FileBackendDBRepoWrapper extends FileBackend { |
||
| 41 | /** @var FileBackend */ |
||
| 42 | protected $backend; |
||
| 43 | /** @var string */ |
||
| 44 | protected $repoName; |
||
| 45 | /** @var Closure */ |
||
| 46 | protected $dbHandleFunc; |
||
| 47 | /** @var ProcessCacheLRU */ |
||
| 48 | protected $resolvedPathCache; |
||
| 49 | /** @var DBConnRef[] */ |
||
| 50 | protected $dbs; |
||
| 51 | |||
| 52 | public function __construct( array $config ) { |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Get the underlying FileBackend that is being wrapped |
||
| 66 | * |
||
| 67 | * @return FileBackend |
||
| 68 | */ |
||
| 69 | public function getInternalBackend() { |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Translate a legacy "title" path to it's "sha1" counterpart |
||
| 75 | * |
||
| 76 | * E.g. mwstore://local-backend/local-public/a/ab/<name>.jpg |
||
| 77 | * => mwstore://local-backend/local-original/x/y/z/<sha1>.jpg |
||
| 78 | * |
||
| 79 | * @param string $path |
||
| 80 | * @param bool $latest |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | public function getBackendPath( $path, $latest = true ) { |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Translate legacy "title" paths to their "sha1" counterparts |
||
| 90 | * |
||
| 91 | * E.g. mwstore://local-backend/local-public/a/ab/<name>.jpg |
||
| 92 | * => mwstore://local-backend/local-original/x/y/z/<sha1>.jpg |
||
| 93 | * |
||
| 94 | * @param array $paths |
||
| 95 | * @param bool $latest |
||
| 96 | * @return array Translated paths in same order |
||
| 97 | */ |
||
| 98 | public function getBackendPaths( array $paths, $latest = true ) { |
||
| 147 | |||
| 148 | protected function doOperationsInternal( array $ops, array $opts ) { |
||
| 151 | |||
| 152 | protected function doQuickOperationsInternal( array $ops ) { |
||
| 155 | |||
| 156 | protected function doPrepare( array $params ) { |
||
| 159 | |||
| 160 | protected function doSecure( array $params ) { |
||
| 163 | |||
| 164 | protected function doPublish( array $params ) { |
||
| 167 | |||
| 168 | protected function doClean( array $params ) { |
||
| 171 | |||
| 172 | public function concatenate( array $params ) { |
||
| 175 | |||
| 176 | public function fileExists( array $params ) { |
||
| 179 | |||
| 180 | public function getFileTimestamp( array $params ) { |
||
| 183 | |||
| 184 | public function getFileSize( array $params ) { |
||
| 187 | |||
| 188 | public function getFileStat( array $params ) { |
||
| 191 | |||
| 192 | public function getFileXAttributes( array $params ) { |
||
| 195 | |||
| 196 | public function getFileSha1Base36( array $params ) { |
||
| 199 | |||
| 200 | public function getFileProps( array $params ) { |
||
| 203 | |||
| 204 | public function streamFile( array $params ) { |
||
| 215 | |||
| 216 | public function getFileContentsMulti( array $params ) { |
||
| 219 | |||
| 220 | public function getLocalReferenceMulti( array $params ) { |
||
| 223 | |||
| 224 | public function getLocalCopyMulti( array $params ) { |
||
| 227 | |||
| 228 | public function getFileHttpUrl( array $params ) { |
||
| 231 | |||
| 232 | public function directoryExists( array $params ) { |
||
| 235 | |||
| 236 | public function getDirectoryList( array $params ) { |
||
| 239 | |||
| 240 | public function getFileList( array $params ) { |
||
| 243 | |||
| 244 | public function getFeatures() { |
||
| 247 | |||
| 248 | public function clearCache( array $paths = null ) { |
||
| 251 | |||
| 252 | public function preloadCache( array $paths ) { |
||
| 256 | |||
| 257 | public function preloadFileStat( array $params ) { |
||
| 260 | |||
| 261 | public function getScopedLocksForOps( array $ops, StatusValue $status ) { |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Get the ultimate original storage path for a file |
||
| 267 | * |
||
| 268 | * Use this when putting a new file into the system |
||
| 269 | * |
||
| 270 | * @param string $sha1 File SHA-1 base36 |
||
| 271 | * @return string |
||
| 272 | */ |
||
| 273 | public function getPathForSHA1( $sha1 ) { |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Get a connection to the repo file registry DB |
||
| 283 | * |
||
| 284 | * @param integer $index |
||
| 285 | * @return DBConnRef |
||
| 286 | */ |
||
| 287 | protected function getDB( $index ) { |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Translates paths found in the "src" or "srcs" keys of a params array |
||
| 297 | * |
||
| 298 | * @param string $function |
||
| 299 | * @param array $params |
||
| 300 | */ |
||
| 301 | protected function translateSrcParams( $function, array $params ) { |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Translates paths when the backend function returns results keyed by paths |
||
| 317 | * |
||
| 318 | * @param string $function |
||
| 319 | * @param array $params |
||
| 320 | * @return array |
||
| 321 | */ |
||
| 322 | protected function translateArrayResults( $function, array $params ) { |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Translate legacy "title" source paths to their "sha1" counterparts |
||
| 339 | * |
||
| 340 | * This leaves destination paths alone since we don't want those to mutate |
||
| 341 | * |
||
| 342 | * @param array $ops |
||
| 343 | * @return array |
||
| 344 | */ |
||
| 345 | protected function mungeOpPaths( array $ops ) { |
||
| 358 | } |
||
| 359 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: