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() |
||
147 | |||
148 | /** |
||
149 | * Create MongoDB Connection. |
||
150 | * |
||
151 | * @param Configuration $config |
||
152 | * |
||
153 | * @throws \InvalidArgumentException |
||
154 | * @throws \RuntimeException |
||
155 | * |
||
156 | * @return Connection |
||
157 | */ |
||
158 | protected function getConnection(Configuration $config) |
||
186 | |||
187 | /** |
||
188 | * {@inheritdoc} |
||
189 | */ |
||
190 | protected function getAnnotationMetadataDriver(array $paths) |
||
194 | |||
195 | /** |
||
196 | * {@inheritdoc} |
||
197 | */ |
||
198 | protected function getXmlMetadataDriver(array $paths, $extension = null) |
||
202 | |||
203 | /** |
||
204 | * {@inheritdoc} |
||
205 | */ |
||
206 | protected function getYamlMetadataDriver(array $paths, $extension = null) |
||
210 | |||
211 | /** |
||
212 | * {@inheritdoc} |
||
213 | * |
||
214 | * @throws \InvalidArgumentException |
||
215 | * |
||
216 | * @return RepositoryFactory|null |
||
217 | */ |
||
218 | protected function getRepositoryFactory() |
||
235 | |||
236 | /** |
||
237 | * Retrieve hydrators path. |
||
238 | * |
||
239 | * @return string |
||
240 | */ |
||
241 | protected function getHydratorsPath() |
||
245 | |||
246 | /** |
||
247 | * Retrieve hydrators namespace. |
||
248 | * |
||
249 | * @return null|string |
||
250 | */ |
||
251 | protected function getHydratorsNamespace() |
||
257 | |||
258 | /** |
||
259 | * Retrieve hydrators generation strategy. |
||
260 | * |
||
261 | * @return int |
||
262 | */ |
||
263 | protected function getHydratorsAutoGeneration() |
||
267 | |||
268 | /** |
||
269 | * Retrieve persistent collections path. |
||
270 | * |
||
271 | * @return string |
||
272 | */ |
||
273 | protected function getPersistentCollectionPath() |
||
277 | |||
278 | /** |
||
279 | * Retrieve persistent collections namespace. |
||
280 | * |
||
281 | * @return null|string |
||
282 | */ |
||
283 | protected function getPersistentCollectionNamespace() |
||
289 | |||
290 | /** |
||
291 | * Retrieve persistent collections generation strategy. |
||
292 | * |
||
293 | * @return int |
||
294 | */ |
||
295 | protected function getAutoGeneratePersistentCollection() |
||
299 | |||
300 | /** |
||
301 | * Get default database. |
||
302 | * |
||
303 | * @return string|null |
||
304 | */ |
||
305 | protected function getDefaultDatabase() |
||
309 | |||
310 | /** |
||
311 | * Retrieve logger callable. |
||
312 | * |
||
313 | * @return callable|null |
||
314 | */ |
||
315 | protected function getLoggerCallable() |
||
327 | |||
328 | /** |
||
329 | * {@inheritdoc} |
||
330 | * |
||
331 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
332 | * @throws \InvalidArgumentException |
||
333 | * @throws \RuntimeException |
||
334 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
335 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
336 | * @throws \UnexpectedValueException |
||
337 | * |
||
338 | * @return Command[] |
||
339 | */ |
||
340 | public function getConsoleCommands() |
||
377 | |||
378 | /** |
||
379 | * {@inheritdoc} |
||
380 | * |
||
381 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
382 | * @throws \InvalidArgumentException |
||
383 | * @throws \RuntimeException |
||
384 | * @throws \UnexpectedValueException |
||
385 | */ |
||
386 | public function getConsoleHelperSet() |
||
392 | } |
||
393 |