Complex classes like RelationalBuilder 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 RelationalBuilder, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
38 | class RelationalBuilder extends AbstractManagerBuilder |
||
39 | { |
||
40 | /** |
||
41 | * Query cache driver. |
||
42 | * |
||
43 | * @var CacheProvider |
||
44 | */ |
||
45 | protected $queryCacheDriver; |
||
46 | |||
47 | /** |
||
48 | * Result cache driver. |
||
49 | * |
||
50 | * @var CacheProvider |
||
51 | */ |
||
52 | protected $resultCacheDriver; |
||
53 | |||
54 | /** |
||
55 | * Naming strategy. |
||
56 | * |
||
57 | * @var NamingStrategy |
||
58 | */ |
||
59 | protected $namingStrategy; |
||
60 | |||
61 | /** |
||
62 | * Quote strategy. |
||
63 | * |
||
64 | * @var QuoteStrategy |
||
65 | */ |
||
66 | protected $quoteStrategy; |
||
67 | |||
68 | /** |
||
69 | * SQL logger. |
||
70 | * |
||
71 | * @var SQLLogger |
||
72 | */ |
||
73 | protected $SQLLogger; |
||
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | protected function getDefaultOptions() |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | protected function wipe() |
||
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | * |
||
109 | * @throws \Doctrine\DBAL\DBALException |
||
110 | * @throws \Doctrine\ORM\ORMException |
||
111 | * @throws \InvalidArgumentException |
||
112 | * @throws \RuntimeException |
||
113 | * @throws \UnexpectedValueException |
||
114 | * |
||
115 | * @return EntityManager |
||
116 | */ |
||
117 | protected function buildManager() |
||
144 | |||
145 | /** |
||
146 | * Set up general manager configurations. |
||
147 | * |
||
148 | * @param Configuration $config |
||
149 | */ |
||
150 | protected function setUpGeneralConfigurations(Configuration $config) |
||
169 | |||
170 | /** |
||
171 | * Set up manager specific configurations. |
||
172 | * |
||
173 | * @param Configuration $config |
||
174 | */ |
||
175 | protected function setUpSpecificConfigurations(Configuration $config) |
||
192 | |||
193 | /** |
||
194 | * {@inheritdoc} |
||
195 | */ |
||
196 | protected function getAnnotationMappingDriver(array $paths) |
||
200 | |||
201 | /** |
||
202 | * {@inheritdoc} |
||
203 | */ |
||
204 | protected function getXmlMappingDriver(array $paths, $extension = null) |
||
210 | |||
211 | /** |
||
212 | * {@inheritdoc} |
||
213 | */ |
||
214 | protected function getYamlMappingDriver(array $paths, $extension = null) |
||
220 | |||
221 | /** |
||
222 | * {@inheritdoc} |
||
223 | * |
||
224 | * @throws \InvalidArgumentException |
||
225 | * |
||
226 | * @return RepositoryFactory|null |
||
227 | */ |
||
228 | protected function getRepositoryFactory() |
||
245 | |||
246 | /** |
||
247 | * Retrieve query cache driver. |
||
248 | * |
||
249 | * @throws \InvalidArgumentException |
||
250 | * |
||
251 | * @return CacheProvider |
||
252 | */ |
||
253 | public function getQueryCacheDriver() |
||
273 | |||
274 | /** |
||
275 | * Set query cache driver. |
||
276 | * |
||
277 | * @param CacheProvider $queryCacheDriver |
||
278 | */ |
||
279 | public function setQueryCacheDriver(CacheProvider $queryCacheDriver) |
||
283 | |||
284 | /** |
||
285 | * Retrieve result cache driver. |
||
286 | * |
||
287 | * @throws \InvalidArgumentException |
||
288 | * |
||
289 | * @return CacheProvider |
||
290 | */ |
||
291 | public function getResultCacheDriver() |
||
311 | |||
312 | /** |
||
313 | * Set result cache driver. |
||
314 | * |
||
315 | * @param CacheProvider $resultCacheDriver |
||
316 | */ |
||
317 | public function setResultCacheDriver(CacheProvider $resultCacheDriver) |
||
321 | |||
322 | /** |
||
323 | * Retrieve naming strategy. |
||
324 | * |
||
325 | * @return NamingStrategy |
||
326 | */ |
||
327 | protected function getNamingStrategy() |
||
341 | |||
342 | /** |
||
343 | * Retrieve quote strategy. |
||
344 | * |
||
345 | * @throws \InvalidArgumentException |
||
346 | * |
||
347 | * @return QuoteStrategy |
||
348 | */ |
||
349 | protected function getQuoteStrategy() |
||
363 | |||
364 | /** |
||
365 | * Retrieve SQL logger. |
||
366 | * |
||
367 | * @return SQLLogger|null |
||
368 | */ |
||
369 | protected function getSQLLogger() |
||
381 | |||
382 | /** |
||
383 | * Retrieve custom DQL string functions. |
||
384 | * |
||
385 | * @return array |
||
386 | */ |
||
387 | protected function getCustomStringFunctions() |
||
399 | |||
400 | /** |
||
401 | * Retrieve custom DQL numeric functions. |
||
402 | * |
||
403 | * @return array |
||
404 | */ |
||
405 | protected function getCustomNumericFunctions() |
||
417 | |||
418 | /** |
||
419 | * Retrieve custom DQL date time functions. |
||
420 | * |
||
421 | * @return array |
||
422 | */ |
||
423 | protected function getCustomDateTimeFunctions() |
||
435 | |||
436 | /** |
||
437 | * Retrieve custom DBAL types. |
||
438 | * |
||
439 | * @return array |
||
440 | */ |
||
441 | protected function getCustomTypes() |
||
453 | |||
454 | /** |
||
455 | * Get custom registered filters. |
||
456 | * |
||
457 | * @return array |
||
458 | */ |
||
459 | protected function getCustomFilters() |
||
471 | |||
472 | /** |
||
473 | * {@inheritdoc} |
||
474 | * |
||
475 | * @throws \Doctrine\DBAL\DBALException |
||
476 | * @throws \Doctrine\ORM\ORMException |
||
477 | * @throws \InvalidArgumentException |
||
478 | * @throws \RuntimeException |
||
479 | * @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
||
480 | * @throws \Symfony\Component\Console\Exception\LogicException |
||
481 | * @throws \UnexpectedValueException |
||
482 | * |
||
483 | * @return Command[] |
||
484 | */ |
||
485 | public function getConsoleCommands() |
||
537 | |||
538 | /** |
||
539 | * {@inheritdoc} |
||
540 | * |
||
541 | * @throws \Doctrine\DBAL\DBALException |
||
542 | * @throws \Doctrine\ORM\ORMException |
||
543 | * @throws \InvalidArgumentException |
||
544 | * @throws \RuntimeException |
||
545 | * @throws \UnexpectedValueException |
||
546 | */ |
||
547 | public function getConsoleHelperSet() |
||
556 | } |
||
557 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: