Complex classes like MongoDBBuilder 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 MongoDBBuilder, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class MongoDBBuilder extends AbstractManagerBuilder |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * Document Manager. |
||
| 35 | * |
||
| 36 | * @var DocumentManager |
||
| 37 | */ |
||
| 38 | protected $manager; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Logger callable. |
||
| 42 | * |
||
| 43 | * @var callable |
||
| 44 | */ |
||
| 45 | protected $loggerCallable; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritdoc} |
||
| 49 | */ |
||
| 50 | protected function getDefaultOptions() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * {@inheritdoc} |
||
| 66 | * |
||
| 67 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
| 68 | * @throws \InvalidArgumentException |
||
| 69 | * @throws \RuntimeException |
||
| 70 | * @throws \UnexpectedValueException |
||
| 71 | * |
||
| 72 | * @return DocumentManager |
||
| 73 | */ |
||
| 74 | public function getManager($force = false) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * {@inheritdoc} |
||
| 89 | */ |
||
| 90 | protected function wipe() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Build Doctrine MongoDB Document Manager. |
||
| 100 | * |
||
| 101 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
| 102 | * @throws \InvalidArgumentException |
||
| 103 | * @throws \RuntimeException |
||
| 104 | * @throws \UnexpectedValueException |
||
| 105 | * |
||
| 106 | * @return DocumentManager |
||
| 107 | */ |
||
| 108 | protected function buildManager() |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Set up general manager configurations. |
||
| 130 | * |
||
| 131 | * @param Configuration $config |
||
| 132 | */ |
||
| 133 | protected function setUpGeneralConfigurations(Configuration $config) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Set up manager specific configurations. |
||
| 155 | * |
||
| 156 | * @param Configuration $config |
||
| 157 | */ |
||
| 158 | protected function setUpSpecificConfigurations(Configuration $config) |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Create MongoDB Connection. |
||
| 185 | * |
||
| 186 | * @param Configuration $config |
||
| 187 | * |
||
| 188 | * @throws \InvalidArgumentException |
||
| 189 | * @throws \RuntimeException |
||
| 190 | * |
||
| 191 | * @return Connection |
||
| 192 | */ |
||
| 193 | protected function getConnection(Configuration $config) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * {@inheritdoc} |
||
| 224 | */ |
||
| 225 | protected function getAnnotationMetadataDriver(array $paths) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * {@inheritdoc} |
||
| 232 | */ |
||
| 233 | protected function getXmlMetadataDriver(array $paths, $extension = null) |
||
| 239 | |||
| 240 | /** |
||
| 241 | * {@inheritdoc} |
||
| 242 | */ |
||
| 243 | protected function getYamlMetadataDriver(array $paths, $extension = null) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * {@inheritdoc} |
||
| 252 | * |
||
| 253 | * @throws \InvalidArgumentException |
||
| 254 | * |
||
| 255 | * @return RepositoryFactory|null |
||
| 256 | */ |
||
| 257 | protected function getRepositoryFactory() |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Retrieve hydrators path. |
||
| 277 | * |
||
| 278 | * @return string |
||
| 279 | */ |
||
| 280 | protected function getHydratorsPath() |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Retrieve hydrators namespace. |
||
| 287 | * |
||
| 288 | * @return null|string |
||
| 289 | */ |
||
| 290 | protected function getHydratorsNamespace() |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Retrieve hydrators generation strategy. |
||
| 299 | * |
||
| 300 | * @return int |
||
| 301 | */ |
||
| 302 | protected function getHydratorsAutoGeneration() |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Retrieve persistent collections path. |
||
| 309 | * |
||
| 310 | * @return string |
||
| 311 | */ |
||
| 312 | protected function getPersistentCollectionPath() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Retrieve persistent collections namespace. |
||
| 319 | * |
||
| 320 | * @return null|string |
||
| 321 | */ |
||
| 322 | protected function getPersistentCollectionNamespace() |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Retrieve persistent collections generation strategy. |
||
| 331 | * |
||
| 332 | * @return int |
||
| 333 | */ |
||
| 334 | protected function getAutoGeneratePersistentCollection() |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Get default database. |
||
| 341 | * |
||
| 342 | * @return string|null |
||
| 343 | */ |
||
| 344 | protected function getDefaultDatabase() |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Retrieve logger callable. |
||
| 351 | * |
||
| 352 | * @return callable|null |
||
| 353 | */ |
||
| 354 | protected function getLoggerCallable() |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Get custom registered filters. |
||
| 369 | * |
||
| 370 | * @return array |
||
| 371 | */ |
||
| 372 | protected function getCustomFilters() |
||
| 384 | |||
| 385 | /** |
||
| 386 | * {@inheritdoc} |
||
| 387 | * |
||
| 388 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
| 389 | * @throws \InvalidArgumentException |
||
| 390 | * @throws \RuntimeException |
||
| 391 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
| 392 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
| 393 | * @throws \UnexpectedValueException |
||
| 394 | * |
||
| 395 | * @return Command[] |
||
| 396 | */ |
||
| 397 | public function getConsoleCommands() |
||
| 434 | |||
| 435 | /** |
||
| 436 | * {@inheritdoc} |
||
| 437 | * |
||
| 438 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
| 439 | * @throws \InvalidArgumentException |
||
| 440 | * @throws \RuntimeException |
||
| 441 | * @throws \UnexpectedValueException |
||
| 442 | */ |
||
| 443 | public function getConsoleHelperSet() |
||
| 449 | } |
||
| 450 |