Complex classes like Results 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 Results, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | class Results |
||
9 | { |
||
10 | /** |
||
11 | * @var string |
||
12 | * @JMS\Type("string") |
||
13 | */ |
||
14 | public $id; |
||
15 | /** |
||
16 | * @var int |
||
17 | * @JMS\Type("integer") |
||
18 | */ |
||
19 | public $totalRecordCount; |
||
20 | /** |
||
21 | * @var string |
||
22 | * @JMS\Type("string") |
||
23 | */ |
||
24 | public $area; |
||
25 | /** |
||
26 | * @var string |
||
27 | * @JMS\Type("string") |
||
28 | */ |
||
29 | public $biasingProfile; |
||
30 | /** |
||
31 | * @var string |
||
32 | * @JMS\Type("string") |
||
33 | */ |
||
34 | public $redirect; |
||
35 | /** |
||
36 | * @var string |
||
37 | * @JMS\Type("string") |
||
38 | */ |
||
39 | public $errors; |
||
40 | /** |
||
41 | * @var string |
||
42 | * @JMS\Type("string") |
||
43 | */ |
||
44 | public $query; |
||
45 | /** |
||
46 | * @var string |
||
47 | * @JMS\Type("string") |
||
48 | */ |
||
49 | public $originalQuery; |
||
50 | /** |
||
51 | * @var string |
||
52 | * @JMS\Type("string") |
||
53 | */ |
||
54 | public $correctedQuery; |
||
55 | /** |
||
56 | * @var Template |
||
57 | * @JMS\Type("GroupByInc\API\Model\Template") |
||
58 | */ |
||
59 | public $template; |
||
60 | /** |
||
61 | * @var PageInfo |
||
62 | * @JMS\Type("GroupByInc\API\Model\PageInfo") |
||
63 | */ |
||
64 | public $pageInfo; |
||
65 | /** |
||
66 | * @var MatchStrategy |
||
67 | * @JMS\Type("GroupByInc\API\Model\MatchStrategy") |
||
68 | */ |
||
69 | public $matchStrategy; |
||
70 | /** |
||
71 | * @var Navigation[] |
||
72 | * @JMS\Type("array<GroupByInc\API\Model\Navigation>") |
||
73 | */ |
||
74 | public $availableNavigation = array(); |
||
75 | /** |
||
76 | * @var Navigation[] |
||
77 | * @JMS\Type("array<GroupByInc\API\Model\Navigation>") |
||
78 | */ |
||
79 | public $selectedNavigation = array(); |
||
80 | /** |
||
81 | * @var Record[] |
||
82 | * @JMS\Type("array<GroupByInc\API\Model\Record>") |
||
83 | */ |
||
84 | public $records = array(); |
||
85 | /** |
||
86 | * @var string[] |
||
87 | * @JMS\Type("array<string>") |
||
88 | */ |
||
89 | public $didYouMean = array(); |
||
90 | /** |
||
91 | * @var string[] |
||
92 | * @JMS\Type("array<string>") |
||
93 | */ |
||
94 | public $relatedQueries = array(); |
||
95 | /** |
||
96 | * @var Request |
||
97 | * @JMS\Type("GroupByInc\API\Request\Request") |
||
98 | */ |
||
99 | public $originalRequest; |
||
100 | /** |
||
101 | * @var string[] |
||
102 | * @JMS\Type("array<string>") |
||
103 | */ |
||
104 | public $rewrites = array(); |
||
105 | /** |
||
106 | * @var Metadata[] |
||
107 | * @JMS\Type("array<GroupByInc\API\Model\Metadata>") |
||
108 | */ |
||
109 | public $siteParams = array(); |
||
110 | /** |
||
111 | * @var string[] |
||
112 | * @JMS\Type("array<string>") |
||
113 | */ |
||
114 | public $warnings = array(); |
||
115 | /** |
||
116 | * @var ResultsMetadata |
||
117 | * @JMS\Type("GroupByInc\API\Model\ResultsMetadata") |
||
118 | */ |
||
119 | public $resultsMetadata; |
||
120 | |||
121 | /** |
||
122 | * @return string The ID of the response. |
||
123 | */ |
||
124 | public function getId() |
||
128 | |||
129 | /** |
||
130 | * @param string $id Set the response ID. |
||
131 | */ |
||
132 | public function setId($id) |
||
136 | |||
137 | /** |
||
138 | * @return string[] A list of spell corrections based on the search term. |
||
139 | */ |
||
140 | public function getDidYouMean() |
||
144 | |||
145 | /** |
||
146 | * @param string[] $didYouMean Set the list. |
||
147 | */ |
||
148 | public function setDidYouMean($didYouMean) |
||
152 | |||
153 | /** |
||
154 | * @return string[] A list of related queries for a given search term. |
||
155 | */ |
||
156 | public function getRelatedQueries() |
||
160 | |||
161 | /** |
||
162 | * @param string[] $relatedQueries Set the related queries for a search term. |
||
163 | */ |
||
164 | public function setRelatedQueries($relatedQueries) |
||
168 | |||
169 | /** |
||
170 | * @return Request The original request which generated these results |
||
171 | */ |
||
172 | public function getOriginalRequest() |
||
176 | |||
177 | /** |
||
178 | * @param Request $originalRequest Set the original request which generated these results |
||
179 | */ |
||
180 | public function setOriginalRequest($originalRequest) |
||
184 | |||
185 | /** |
||
186 | * @return Record[] A list of the records for this search and navigation state. |
||
187 | */ |
||
188 | public function getRecords() |
||
192 | |||
193 | /** |
||
194 | * @param Record[] $records Set the records. |
||
195 | */ |
||
196 | public function setRecords($records) |
||
200 | |||
201 | /** |
||
202 | * @return Template If a rule has fired, the associated template will be returned. |
||
203 | */ |
||
204 | public function getTemplate() |
||
208 | |||
209 | /** |
||
210 | * @param Template $template Set the template. |
||
211 | */ |
||
212 | public function setTemplate($template) |
||
216 | |||
217 | /** |
||
218 | * @return PageInfo Information about the results page. |
||
219 | */ |
||
220 | public function getPageInfo() |
||
224 | |||
225 | /** |
||
226 | * @param PageInfo $pageInfo Set the page info. |
||
227 | */ |
||
228 | public function setPageInfo($pageInfo) |
||
232 | |||
233 | /** |
||
234 | * @return MatchStrategy associated with this Results object |
||
235 | */ |
||
236 | public function getMatchStrategy() |
||
240 | |||
241 | /** |
||
242 | * @param MatchStrategy $matchStrategy Set the match strategy |
||
243 | */ |
||
244 | public function setMatchStrategy($matchStrategy) |
||
248 | |||
249 | /** |
||
250 | * @return Navigation[] A list of all the ways in which you can filter the current result set. |
||
251 | */ |
||
252 | public function getAvailableNavigation() |
||
256 | |||
257 | /** |
||
258 | * @param Navigation[] $availableNavigation Set the available navigation. |
||
259 | */ |
||
260 | public function setAvailableNavigation($availableNavigation) |
||
264 | |||
265 | /** |
||
266 | * @return Navigation[] A list of the currently selected navigations. Also known as breadcrumbs. |
||
267 | */ |
||
268 | public function getSelectedNavigation() |
||
272 | |||
273 | /** |
||
274 | * @param Navigation[] $selectedNavigation Set the selected navigations. |
||
275 | */ |
||
276 | public function setSelectedNavigation($selectedNavigation) |
||
280 | |||
281 | /** |
||
282 | * @return string A URL to redirect to based on this search term. |
||
283 | */ |
||
284 | public function getRedirect() |
||
288 | |||
289 | /** |
||
290 | * @param string $redirect Set the redirect. |
||
291 | */ |
||
292 | public function setRedirect($redirect) |
||
296 | |||
297 | /** |
||
298 | * @return string representation of any errors encountered. |
||
299 | */ |
||
300 | public function getErrors() |
||
304 | |||
305 | /** |
||
306 | * @param string $errors Set errors. |
||
307 | */ |
||
308 | public function setErrors($errors) |
||
312 | |||
313 | /** |
||
314 | * @return int A count of the total number of records in this search and navigation state. |
||
315 | */ |
||
316 | public function getTotalRecordCount() |
||
320 | |||
321 | /** |
||
322 | * @param int $totalRecordCount Set the total record count. |
||
323 | */ |
||
324 | public function setTotalRecordCount($totalRecordCount) |
||
328 | |||
329 | /** |
||
330 | * @return Metadata[] A list of metadata as set in the area management section of the command center. |
||
331 | */ |
||
332 | public function getSiteParams() |
||
336 | |||
337 | /** |
||
338 | * @param Metadata[] $siteParams Set the site metadata. |
||
339 | */ |
||
340 | public function setSiteParams($siteParams) |
||
344 | |||
345 | /** |
||
346 | * @return string The query sent to the bridge. |
||
347 | */ |
||
348 | public function getQuery() |
||
352 | |||
353 | /** |
||
354 | * @param string $query Sets the query to the bridge. |
||
355 | */ |
||
356 | public function setQuery($query) |
||
360 | |||
361 | /** |
||
362 | * @return string The original query sent to the search service. |
||
363 | */ |
||
364 | public function getOriginalQuery() |
||
368 | |||
369 | /** |
||
370 | * @param string $originalQuery Sets the original query sent to the search service. |
||
371 | */ |
||
372 | public function setOriginalQuery($originalQuery) |
||
376 | |||
377 | /** |
||
378 | * @return string The corrected query sent to the engine, if auto-correction is enabled. |
||
379 | */ |
||
380 | public function getCorrectedQuery() |
||
384 | |||
385 | /** |
||
386 | * @param string $correctedQuery Sets the corrected query sent to the engine, if auto-correction is enabled. |
||
387 | */ |
||
388 | public function setCorrectedQuery($correctedQuery) |
||
392 | |||
393 | /** |
||
394 | * @return string[] A list of rewrites (spellings, synonyms, etc...) that occurred. |
||
395 | */ |
||
396 | public function getRewrites() |
||
400 | |||
401 | /** |
||
402 | * @param string[] $rewrites Sets the rewrites that occurred. |
||
403 | */ |
||
404 | public function setRewrites($rewrites) |
||
408 | |||
409 | /** |
||
410 | * @return string The area that the search fired against. |
||
411 | */ |
||
412 | public function getArea() |
||
416 | |||
417 | /** |
||
418 | * @param string $area Sets the area. |
||
419 | */ |
||
420 | public function setArea($area) |
||
424 | |||
425 | /** |
||
426 | * @return string |
||
427 | */ |
||
428 | public function getBiasingProfile() |
||
432 | |||
433 | /** |
||
434 | * @param string $biasingProfile |
||
435 | */ |
||
436 | public function setBiasingProfile($biasingProfile) |
||
440 | |||
441 | /** |
||
442 | * @return string[] |
||
443 | */ |
||
444 | public function getWarnings() |
||
448 | |||
449 | /** |
||
450 | * @param string[] $warnings |
||
451 | */ |
||
452 | public function setWarnings($warnings) |
||
456 | |||
457 | /** |
||
458 | * @return ResultsMetadata |
||
459 | */ |
||
460 | public function getResultsMetadata() |
||
464 | |||
465 | /** |
||
466 | * @param ResultsMetadata $resultsMetadata |
||
467 | */ |
||
468 | public function setResultsMetadata($resultsMetadata) |
||
472 | } |
||
473 |