Complex classes like ProxyQuery 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 ProxyQuery, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | class ProxyQuery implements ProxyQueryInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var QueryBuilder |
||
27 | */ |
||
28 | protected $queryBuilder; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $sortBy; |
||
34 | |||
35 | /** |
||
36 | * @var mixed |
||
37 | */ |
||
38 | protected $sortOrder; |
||
39 | |||
40 | /** |
||
41 | * @var int |
||
42 | */ |
||
43 | protected $uniqueParameterId; |
||
44 | |||
45 | /** |
||
46 | * @var string[] |
||
47 | */ |
||
48 | protected $entityJoinAliases; |
||
49 | |||
50 | /** |
||
51 | * The map of query hints. |
||
52 | * |
||
53 | * @var array<string,mixed> |
||
54 | */ |
||
55 | private $hints = []; |
||
56 | |||
57 | /** |
||
58 | * @param QueryBuilder $queryBuilder |
||
59 | */ |
||
60 | public function __construct($queryBuilder) |
||
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | public function __call($name, $args) |
||
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | public function __get($name) |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | public function __clone() |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | public function execute(array $params = [], $hydrationMode = null) |
||
149 | |||
150 | /** |
||
151 | * {@inheritdoc} |
||
152 | */ |
||
153 | public function setSortBy($parentAssociationMappings, $fieldMapping) |
||
160 | |||
161 | /** |
||
162 | * {@inheritdoc} |
||
163 | */ |
||
164 | public function getSortBy() |
||
168 | |||
169 | /** |
||
170 | * {@inheritdoc} |
||
171 | */ |
||
172 | public function setSortOrder($sortOrder) |
||
178 | |||
179 | /** |
||
180 | * {@inheritdoc} |
||
181 | */ |
||
182 | public function getSortOrder() |
||
186 | |||
187 | /** |
||
188 | * {@inheritdoc} |
||
189 | */ |
||
190 | public function getSingleScalarResult() |
||
196 | |||
197 | /** |
||
198 | * @return mixed |
||
199 | */ |
||
200 | public function getQueryBuilder() |
||
204 | |||
205 | /** |
||
206 | * {@inheritdoc} |
||
207 | */ |
||
208 | public function setFirstResult($firstResult) |
||
214 | |||
215 | /** |
||
216 | * {@inheritdoc} |
||
217 | */ |
||
218 | public function getFirstResult() |
||
222 | |||
223 | /** |
||
224 | * {@inheritdoc} |
||
225 | */ |
||
226 | public function setMaxResults($maxResults) |
||
232 | |||
233 | /** |
||
234 | * {@inheritdoc} |
||
235 | */ |
||
236 | public function getMaxResults() |
||
240 | |||
241 | /** |
||
242 | * {@inheritdoc} |
||
243 | */ |
||
244 | public function getUniqueParameterId() |
||
248 | |||
249 | /** |
||
250 | * {@inheritdoc} |
||
251 | */ |
||
252 | public function entityJoin(array $associationMappings) |
||
286 | |||
287 | /** |
||
288 | * Sets a {@see \Doctrine\ORM\Query} hint. If the hint name is not recognized, it is silently ignored. |
||
289 | * |
||
290 | * @param string $name the name of the hint |
||
291 | * @param mixed $value the value of the hint |
||
292 | * |
||
293 | * @return ProxyQueryInterface |
||
294 | * |
||
295 | * @see \Doctrine\ORM\Query::setHint |
||
296 | * @see \Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER |
||
297 | */ |
||
298 | final public function setHint($name, $value) |
||
304 | |||
305 | /** |
||
306 | * This method alters the query to return a clean set of object with a working |
||
307 | * set of Object. |
||
308 | * |
||
309 | * @param QueryBuilder $queryBuilder |
||
310 | * |
||
311 | * @return QueryBuilder |
||
312 | */ |
||
313 | protected function getFixedQueryBuilder(QueryBuilder $queryBuilder) |
||
380 | |||
381 | private function addOrderedColumns(QueryBuilder $queryBuilder) |
||
391 | } |
||
392 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.