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 |
||
| 30 | class ModelManager implements ModelManagerInterface |
||
| 31 | { |
||
| 32 | public const ID_SEPARATOR = '-'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var ManagerRegistry |
||
| 36 | */ |
||
| 37 | protected $registry; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var PropertyAccessorInterface |
||
| 41 | */ |
||
| 42 | private $propertyAccessor; |
||
| 43 | |||
| 44 | public function __construct(ManagerRegistry $registry, ?PropertyAccessorInterface $propertyAccessor = null) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * {@inheritdoc} |
||
| 52 | */ |
||
| 53 | public function getMetadata($class) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Returns the model's metadata holding the fully qualified property, and the last |
||
| 60 | * property name. |
||
| 61 | * |
||
| 62 | * @param string $baseClass The base class of the model holding the fully qualified property |
||
| 63 | * @param string $propertyFullName The name of the fully qualified property (dot ('.') separated |
||
| 64 | * property string) |
||
| 65 | * |
||
| 66 | * @return array( |
||
|
|
|||
| 67 | * \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $parentMetadata, |
||
| 68 | * string $lastPropertyName, |
||
| 69 | * array $parentAssociationMappings |
||
| 70 | * ) |
||
| 71 | */ |
||
| 72 | public function getParentMetadataForProperty($baseClass, $propertyFullName) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * {@inheritdoc} |
||
| 90 | */ |
||
| 91 | public function hasMetadata($class) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * {@inheritdoc} |
||
| 98 | */ |
||
| 99 | public function getNewFieldDescriptionInstance($class, $name, array $options = []) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * {@inheritdoc} |
||
| 134 | */ |
||
| 135 | public function create($object) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * {@inheritdoc} |
||
| 144 | */ |
||
| 145 | public function update($object) |
||
| 151 | |||
| 152 | /** |
||
| 153 | * {@inheritdoc} |
||
| 154 | */ |
||
| 155 | public function delete($object) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * {@inheritdoc} |
||
| 164 | */ |
||
| 165 | public function find($class, $id) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * {@inheritdoc} |
||
| 186 | */ |
||
| 187 | public function findBy($class, array $criteria = []) |
||
| 191 | |||
| 192 | /** |
||
| 193 | * {@inheritdoc} |
||
| 194 | */ |
||
| 195 | public function findOneBy($class, array $criteria = []) |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @param object|string $class |
||
| 202 | * |
||
| 203 | * @throw \RuntimeException |
||
| 204 | * |
||
| 205 | * @return \Doctrine\ODM\MongoDB\DocumentManager |
||
| 206 | */ |
||
| 207 | public function getDocumentManager($class) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * {@inheritdoc} |
||
| 224 | */ |
||
| 225 | public function getParentFieldDescription($parentAssociationMapping, $class) |
||
| 239 | |||
| 240 | /** |
||
| 241 | * {@inheritdoc} |
||
| 242 | */ |
||
| 243 | public function createQuery($class, $alias = 'o') |
||
| 249 | |||
| 250 | /** |
||
| 251 | * {@inheritdoc} |
||
| 252 | */ |
||
| 253 | public function executeQuery($query) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * {@inheritdoc} |
||
| 264 | */ |
||
| 265 | public function getModelIdentifier($class) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * {@inheritdoc} |
||
| 272 | */ |
||
| 273 | public function getIdentifierValues($document) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * {@inheritdoc} |
||
| 280 | */ |
||
| 281 | public function getIdentifierFieldNames($class) |
||
| 285 | |||
| 286 | /** |
||
| 287 | * {@inheritdoc} |
||
| 288 | */ |
||
| 289 | public function getNormalizedIdentifier($document) |
||
| 308 | |||
| 309 | /** |
||
| 310 | * {@inheritdoc} |
||
| 311 | */ |
||
| 312 | public function getUrlSafeIdentifier($document) |
||
| 316 | |||
| 317 | /** |
||
| 318 | * {@inheritdoc} |
||
| 319 | */ |
||
| 320 | public function addIdentifiersToQuery($class, ProxyQueryInterface $queryProxy, array $idx) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * {@inheritdoc} |
||
| 328 | */ |
||
| 329 | public function batchDelete($class, ProxyQueryInterface $queryProxy) |
||
| 349 | |||
| 350 | /** |
||
| 351 | * {@inheritdoc} |
||
| 352 | */ |
||
| 353 | public function getDataSourceIterator(DatagridInterface $datagrid, array $fields, $firstResult = null, $maxResult = null) |
||
| 363 | |||
| 364 | /** |
||
| 365 | * {@inheritdoc} |
||
| 366 | */ |
||
| 367 | public function getExportFields($class) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * {@inheritdoc} |
||
| 376 | */ |
||
| 377 | public function getModelInstance($class) |
||
| 396 | |||
| 397 | /** |
||
| 398 | * {@inheritdoc} |
||
| 399 | */ |
||
| 400 | public function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid) |
||
| 418 | |||
| 419 | /** |
||
| 420 | * {@inheritdoc} |
||
| 421 | */ |
||
| 422 | public function getPaginationParameters(DatagridInterface $datagrid, $page) |
||
| 433 | |||
| 434 | /** |
||
| 435 | * {@inheritdoc} |
||
| 436 | */ |
||
| 437 | public function getDefaultSortValues($class) |
||
| 446 | |||
| 447 | public function getDefaultPerPageOptions(string $class): array |
||
| 451 | |||
| 452 | /** |
||
| 453 | * {@inheritdoc} |
||
| 454 | */ |
||
| 455 | public function modelTransform($class, $instance) |
||
| 459 | |||
| 460 | /** |
||
| 461 | * {@inheritdoc} |
||
| 462 | */ |
||
| 463 | public function modelReverseTransform($class, array $array = []) |
||
| 476 | |||
| 477 | /** |
||
| 478 | * {@inheritdoc} |
||
| 479 | */ |
||
| 480 | public function getModelCollectionInstance($class) |
||
| 484 | |||
| 485 | /** |
||
| 486 | * {@inheritdoc} |
||
| 487 | */ |
||
| 488 | public function collectionClear(&$collection) |
||
| 492 | |||
| 493 | /** |
||
| 494 | * {@inheritdoc} |
||
| 495 | */ |
||
| 496 | public function collectionHasElement(&$collection, &$element) |
||
| 500 | |||
| 501 | /** |
||
| 502 | * {@inheritdoc} |
||
| 503 | */ |
||
| 504 | public function collectionAddElement(&$collection, &$element) |
||
| 508 | |||
| 509 | /** |
||
| 510 | * {@inheritdoc} |
||
| 511 | */ |
||
| 512 | public function collectionRemoveElement(&$collection, &$element) |
||
| 516 | |||
| 517 | /** |
||
| 518 | * NEXT_MAJOR: Remove this method. |
||
| 519 | * |
||
| 520 | * @deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x, to be removed in 4.0.'. |
||
| 521 | * |
||
| 522 | * @param string $property |
||
| 523 | * |
||
| 524 | * @return mixed |
||
| 525 | */ |
||
| 526 | protected function camelize($property) |
||
| 535 | |||
| 536 | private function getFieldName(ClassMetadata $metadata, string $name): string |
||
| 548 | |||
| 549 | private function isFieldAlreadySorted(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid): bool |
||
| 560 | } |
||
| 561 |
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.