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 |
||
27 | class ModelManager implements ModelManagerInterface |
||
28 | { |
||
29 | public const ID_SEPARATOR = '-'; |
||
30 | protected $registry; |
||
31 | |||
32 | public function __construct(ManagerRegistry $registry) |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | public function getMetadata($class) |
||
44 | |||
45 | /** |
||
46 | * Returns the model's metadata holding the fully qualified property, and the last |
||
47 | * property name. |
||
48 | * |
||
49 | * @param string $baseClass The base class of the model holding the fully qualified property |
||
50 | * @param string $propertyFullName The name of the fully qualified property (dot ('.') separated |
||
51 | * property string) |
||
52 | * |
||
53 | * @return array( |
||
|
|||
54 | * \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $parentMetadata, |
||
55 | * string $lastPropertyName, |
||
56 | * array $parentAssociationMappings |
||
57 | * ) |
||
58 | */ |
||
59 | public function getParentMetadataForProperty($baseClass, $propertyFullName) |
||
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | public function hasMetadata($class) |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | public function getNewFieldDescriptionInstance($class, $name, array $options = []) |
||
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | public function create($object): void |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function update($object): void |
||
138 | |||
139 | /** |
||
140 | * {@inheritdoc} |
||
141 | */ |
||
142 | public function delete($object): void |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | public function find($class, $id) |
||
170 | |||
171 | /** |
||
172 | * {@inheritdoc} |
||
173 | */ |
||
174 | public function findBy($class, array $criteria = []) |
||
178 | |||
179 | /** |
||
180 | * {@inheritdoc} |
||
181 | */ |
||
182 | public function findOneBy($class, array $criteria = []) |
||
186 | |||
187 | /** |
||
188 | * @param string $class |
||
189 | * |
||
190 | * @throw \RuntimeException |
||
191 | * |
||
192 | * @return \Doctrine\ODM\MongoDB\DocumentManager |
||
193 | */ |
||
194 | public function getDocumentManager($class) |
||
208 | |||
209 | /** |
||
210 | * {@inheritdoc} |
||
211 | */ |
||
212 | public function getParentFieldDescription($parentAssociationMapping, $class) |
||
226 | |||
227 | /** |
||
228 | * {@inheritdoc} |
||
229 | */ |
||
230 | public function createQuery($class, $alias = 'o') |
||
236 | |||
237 | /** |
||
238 | * {@inheritdoc} |
||
239 | */ |
||
240 | public function executeQuery($query) |
||
248 | |||
249 | /** |
||
250 | * {@inheritdoc} |
||
251 | */ |
||
252 | public function getModelIdentifier($class) |
||
256 | |||
257 | /** |
||
258 | * {@inheritdoc} |
||
259 | */ |
||
260 | public function getIdentifierValues($document) |
||
264 | |||
265 | /** |
||
266 | * {@inheritdoc} |
||
267 | */ |
||
268 | public function getIdentifierFieldNames($class) |
||
272 | |||
273 | /** |
||
274 | * {@inheritdoc} |
||
275 | */ |
||
276 | public function getNormalizedIdentifier($document) |
||
291 | |||
292 | /** |
||
293 | * {@inheritdoc} |
||
294 | */ |
||
295 | public function getUrlsafeIdentifier($entity) |
||
299 | |||
300 | /** |
||
301 | * {@inheritdoc} |
||
302 | */ |
||
303 | public function addIdentifiersToQuery($class, ProxyQueryInterface $queryProxy, array $idx): void |
||
308 | |||
309 | /** |
||
310 | * {@inheritdoc} |
||
311 | */ |
||
312 | public function batchDelete($class, ProxyQueryInterface $queryProxy): void |
||
332 | |||
333 | /** |
||
334 | * {@inheritdoc} |
||
335 | */ |
||
336 | public function getDataSourceIterator(DatagridInterface $datagrid, array $fields, $firstResult = null, $maxResult = null) |
||
346 | |||
347 | /** |
||
348 | * {@inheritdoc} |
||
349 | */ |
||
350 | public function getExportFields($class) |
||
356 | |||
357 | /** |
||
358 | * {@inheritdoc} |
||
359 | */ |
||
360 | public function getModelInstance($class) |
||
364 | |||
365 | /** |
||
366 | * {@inheritdoc} |
||
367 | */ |
||
368 | public function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid) |
||
386 | |||
387 | /** |
||
388 | * {@inheritdoc} |
||
389 | */ |
||
390 | public function getPaginationParameters(DatagridInterface $datagrid, $page) |
||
401 | |||
402 | /** |
||
403 | * {@inheritdoc} |
||
404 | */ |
||
405 | public function getDefaultSortValues($class) |
||
414 | |||
415 | /** |
||
416 | * {@inheritdoc} |
||
417 | */ |
||
418 | public function modelTransform($class, $instance) |
||
422 | |||
423 | /** |
||
424 | * {@inheritdoc} |
||
425 | */ |
||
426 | public function modelReverseTransform($class, array $array = []) |
||
468 | |||
469 | /** |
||
470 | * {@inheritdoc} |
||
471 | */ |
||
472 | public function getModelCollectionInstance($class) |
||
476 | |||
477 | /** |
||
478 | * {@inheritdoc} |
||
479 | */ |
||
480 | public function collectionClear(&$collection) |
||
484 | |||
485 | /** |
||
486 | * {@inheritdoc} |
||
487 | */ |
||
488 | public function collectionHasElement(&$collection, &$element) |
||
492 | |||
493 | /** |
||
494 | * {@inheritdoc} |
||
495 | */ |
||
496 | public function collectionAddElement(&$collection, &$element) |
||
500 | |||
501 | /** |
||
502 | * {@inheritdoc} |
||
503 | */ |
||
504 | public function collectionRemoveElement(&$collection, &$element) |
||
508 | |||
509 | /** |
||
510 | * method taken from PropertyPath. |
||
511 | * |
||
512 | * @param string $property |
||
513 | * |
||
514 | * @return mixed |
||
515 | */ |
||
516 | protected function camelize($property) |
||
520 | |||
521 | private function isFieldAlreadySorted(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid): bool |
||
532 | } |
||
533 |
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.