Complex classes like ModelManager 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 ModelManager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class ModelManager implements ModelManagerInterface |
||
| 29 | { |
||
| 30 | public const ID_SEPARATOR = '-'; |
||
| 31 | protected $registry; |
||
| 32 | |||
| 33 | public function __construct(ManagerRegistry $registry) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * {@inheritdoc} |
||
| 40 | */ |
||
| 41 | public function getMetadata($class) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Returns the model's metadata holding the fully qualified property, and the last |
||
| 48 | * property name. |
||
| 49 | * |
||
| 50 | * @param string $baseClass The base class of the model holding the fully qualified property |
||
| 51 | * @param string $propertyFullName The name of the fully qualified property (dot ('.') separated |
||
| 52 | * property string) |
||
| 53 | * |
||
| 54 | * @return array( |
||
|
|
|||
| 55 | * \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $parentMetadata, |
||
| 56 | * string $lastPropertyName, |
||
| 57 | * array $parentAssociationMappings |
||
| 58 | * ) |
||
| 59 | */ |
||
| 60 | public function getParentMetadataForProperty($baseClass, $propertyFullName) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritdoc} |
||
| 78 | */ |
||
| 79 | public function hasMetadata($class) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * {@inheritdoc} |
||
| 86 | */ |
||
| 87 | public function getNewFieldDescriptionInstance($class, $name, array $options = []) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * {@inheritdoc} |
||
| 122 | */ |
||
| 123 | public function create($object) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * {@inheritdoc} |
||
| 132 | */ |
||
| 133 | public function update($object) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * {@inheritdoc} |
||
| 142 | */ |
||
| 143 | public function delete($object) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * {@inheritdoc} |
||
| 152 | */ |
||
| 153 | public function find($class, $id) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritdoc} |
||
| 174 | */ |
||
| 175 | public function findBy($class, array $criteria = []) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * {@inheritdoc} |
||
| 182 | */ |
||
| 183 | public function findOneBy($class, array $criteria = []) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @param object|string $class |
||
| 190 | * |
||
| 191 | * @throw \RuntimeException |
||
| 192 | * |
||
| 193 | * @return \Doctrine\ODM\MongoDB\DocumentManager |
||
| 194 | */ |
||
| 195 | public function getDocumentManager($class) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * {@inheritdoc} |
||
| 212 | */ |
||
| 213 | public function getParentFieldDescription($parentAssociationMapping, $class) |
||
| 227 | |||
| 228 | /** |
||
| 229 | * {@inheritdoc} |
||
| 230 | */ |
||
| 231 | public function createQuery($class, $alias = 'o') |
||
| 237 | |||
| 238 | /** |
||
| 239 | * {@inheritdoc} |
||
| 240 | */ |
||
| 241 | public function executeQuery($query) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * {@inheritdoc} |
||
| 252 | */ |
||
| 253 | public function getModelIdentifier($class) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * {@inheritdoc} |
||
| 260 | */ |
||
| 261 | public function getIdentifierValues($document) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * {@inheritdoc} |
||
| 268 | */ |
||
| 269 | public function getIdentifierFieldNames($class) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * {@inheritdoc} |
||
| 276 | */ |
||
| 277 | public function getNormalizedIdentifier($document) |
||
| 296 | |||
| 297 | /** |
||
| 298 | * {@inheritdoc} |
||
| 299 | */ |
||
| 300 | public function getUrlSafeIdentifier($document) |
||
| 304 | |||
| 305 | /** |
||
| 306 | * {@inheritdoc} |
||
| 307 | */ |
||
| 308 | public function addIdentifiersToQuery($class, ProxyQueryInterface $queryProxy, array $idx) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * {@inheritdoc} |
||
| 316 | */ |
||
| 317 | public function batchDelete($class, ProxyQueryInterface $queryProxy) |
||
| 337 | |||
| 338 | /** |
||
| 339 | * {@inheritdoc} |
||
| 340 | */ |
||
| 341 | public function getDataSourceIterator(DatagridInterface $datagrid, array $fields, $firstResult = null, $maxResult = null) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * {@inheritdoc} |
||
| 354 | */ |
||
| 355 | public function getExportFields($class) |
||
| 361 | |||
| 362 | /** |
||
| 363 | * {@inheritdoc} |
||
| 364 | */ |
||
| 365 | public function getModelInstance($class) |
||
| 369 | |||
| 370 | /** |
||
| 371 | * {@inheritdoc} |
||
| 372 | */ |
||
| 373 | public function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid) |
||
| 391 | |||
| 392 | /** |
||
| 393 | * {@inheritdoc} |
||
| 394 | */ |
||
| 395 | public function getPaginationParameters(DatagridInterface $datagrid, $page) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * {@inheritdoc} |
||
| 409 | */ |
||
| 410 | public function getDefaultSortValues($class) |
||
| 419 | |||
| 420 | public function getDefaultPerPageOptions(string $class): array |
||
| 424 | |||
| 425 | /** |
||
| 426 | * {@inheritdoc} |
||
| 427 | */ |
||
| 428 | public function modelTransform($class, $instance) |
||
| 432 | |||
| 433 | /** |
||
| 434 | * {@inheritdoc} |
||
| 435 | */ |
||
| 436 | public function modelReverseTransform($class, array $array = []) |
||
| 478 | |||
| 479 | /** |
||
| 480 | * {@inheritdoc} |
||
| 481 | */ |
||
| 482 | public function getModelCollectionInstance($class) |
||
| 486 | |||
| 487 | /** |
||
| 488 | * {@inheritdoc} |
||
| 489 | */ |
||
| 490 | public function collectionClear(&$collection) |
||
| 494 | |||
| 495 | /** |
||
| 496 | * {@inheritdoc} |
||
| 497 | */ |
||
| 498 | public function collectionHasElement(&$collection, &$element) |
||
| 502 | |||
| 503 | /** |
||
| 504 | * {@inheritdoc} |
||
| 505 | */ |
||
| 506 | public function collectionAddElement(&$collection, &$element) |
||
| 510 | |||
| 511 | /** |
||
| 512 | * {@inheritdoc} |
||
| 513 | */ |
||
| 514 | public function collectionRemoveElement(&$collection, &$element) |
||
| 518 | |||
| 519 | /** |
||
| 520 | * method taken from PropertyPath. |
||
| 521 | * |
||
| 522 | * @param string $property |
||
| 523 | * |
||
| 524 | * @return mixed |
||
| 525 | */ |
||
| 526 | protected function camelize($property) |
||
| 530 | |||
| 531 | private function isFieldAlreadySorted(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid): bool |
||
| 542 | } |
||
| 543 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.