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 |
||
| 25 | class ModelManager implements ModelManagerInterface |
||
| 26 | { |
||
| 27 | const ID_SEPARATOR = '-'; |
||
| 28 | protected $registry; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param \Symfony\Bridge\Doctrine\ManagerRegistry $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 = array()) |
||
| 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) |
||
| 154 | { |
||
| 155 | if (!isset($id)) { |
||
| 156 | return; |
||
| 157 | } |
||
| 158 | |||
| 159 | $documentManager = $this->getDocumentManager($class); |
||
| 160 | |||
| 161 | if (is_numeric($id)) { |
||
| 162 | $value = $documentManager->getRepository($class)->find(intval($id)); |
||
| 163 | |||
| 164 | if (!empty($value)) { |
||
| 165 | return $value; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | return $documentManager->getRepository($class)->find($id); |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritdoc} |
||
| 174 | */ |
||
| 175 | public function findBy($class, array $criteria = array()) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * {@inheritdoc} |
||
| 182 | */ |
||
| 183 | public function findOneBy($class, array $criteria = array()) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @param 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) |
||
| 292 | |||
| 293 | /** |
||
| 294 | * {@inheritdoc} |
||
| 295 | */ |
||
| 296 | public function getUrlsafeIdentifier($entity) |
||
| 297 | { |
||
| 298 | return $this->getNormalizedIdentifier($entity); |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * {@inheritdoc} |
||
| 303 | */ |
||
| 304 | public function addIdentifiersToQuery($class, ProxyQueryInterface $queryProxy, array $idx) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * {@inheritdoc} |
||
| 312 | */ |
||
| 313 | public function batchDelete($class, ProxyQueryInterface $queryProxy) |
||
| 333 | |||
| 334 | /** |
||
| 335 | * {@inheritdoc} |
||
| 336 | */ |
||
| 337 | public function getDataSourceIterator(DatagridInterface $datagrid, array $fields, $firstResult = null, $maxResult = null) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * {@inheritdoc} |
||
| 350 | */ |
||
| 351 | public function getExportFields($class) |
||
| 357 | |||
| 358 | /** |
||
| 359 | * {@inheritdoc} |
||
| 360 | */ |
||
| 361 | public function getModelInstance($class) |
||
| 365 | |||
| 366 | /** |
||
| 367 | * {@inheritdoc} |
||
| 368 | */ |
||
| 369 | public function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid) |
||
| 387 | |||
| 388 | /** |
||
| 389 | * {@inheritdoc} |
||
| 390 | */ |
||
| 391 | public function getPaginationParameters(DatagridInterface $datagrid, $page) |
||
| 400 | |||
| 401 | /** |
||
| 402 | * {@inheritdoc} |
||
| 403 | */ |
||
| 404 | public function getDefaultSortValues($class) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * {@inheritdoc} |
||
| 416 | */ |
||
| 417 | public function modelTransform($class, $instance) |
||
| 421 | |||
| 422 | /** |
||
| 423 | * {@inheritdoc} |
||
| 424 | */ |
||
| 425 | public function modelReverseTransform($class, array $array = array()) |
||
| 467 | |||
| 468 | /** |
||
| 469 | * {@inheritdoc} |
||
| 470 | */ |
||
| 471 | public function getModelCollectionInstance($class) |
||
| 475 | |||
| 476 | /** |
||
| 477 | * {@inheritdoc} |
||
| 478 | */ |
||
| 479 | public function collectionClear(&$collection) |
||
| 483 | |||
| 484 | /** |
||
| 485 | * {@inheritdoc} |
||
| 486 | */ |
||
| 487 | public function collectionHasElement(&$collection, &$element) |
||
| 491 | |||
| 492 | /** |
||
| 493 | * {@inheritdoc} |
||
| 494 | */ |
||
| 495 | public function collectionAddElement(&$collection, &$element) |
||
| 499 | |||
| 500 | /** |
||
| 501 | * {@inheritdoc} |
||
| 502 | */ |
||
| 503 | public function collectionRemoveElement(&$collection, &$element) |
||
| 507 | |||
| 508 | /** |
||
| 509 | * method taken from PropertyPath. |
||
| 510 | * |
||
| 511 | * @param string $property |
||
| 512 | * |
||
| 513 | * @return mixed |
||
| 514 | */ |
||
| 515 | protected function camelize($property) |
||
| 519 | } |
||
| 520 |
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.