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 |
||
| 7 | class Results |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var string |
||
| 11 | * @JMS\Type("string") |
||
| 12 | */ |
||
| 13 | public $id; |
||
| 14 | /** |
||
| 15 | * @var int |
||
| 16 | * @JMS\Type("integer") |
||
| 17 | */ |
||
| 18 | public $totalRecordCount; |
||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | * @JMS\Type("string") |
||
| 22 | */ |
||
| 23 | public $area; |
||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | * @JMS\Type("string") |
||
| 27 | */ |
||
| 28 | public $biasingProfile; |
||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | * @JMS\Type("string") |
||
| 32 | */ |
||
| 33 | public $redirect; |
||
| 34 | /** |
||
| 35 | * @var string |
||
| 36 | * @JMS\Type("string") |
||
| 37 | */ |
||
| 38 | public $errors; |
||
| 39 | /** |
||
| 40 | * @var string |
||
| 41 | * @JMS\Type("string") |
||
| 42 | */ |
||
| 43 | public $query; |
||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | * @JMS\Type("string") |
||
| 47 | */ |
||
| 48 | public $originalQuery; |
||
| 49 | /** |
||
| 50 | * @var string |
||
| 51 | * @JMS\Type("string") |
||
| 52 | */ |
||
| 53 | public $correctedQuery; |
||
| 54 | /** |
||
| 55 | * @var Template |
||
| 56 | * @JMS\Type("GroupByInc\API\Model\Template") |
||
| 57 | */ |
||
| 58 | public $template; |
||
| 59 | /** |
||
| 60 | * @var PageInfo |
||
| 61 | * @JMS\Type("GroupByInc\API\Model\PageInfo") |
||
| 62 | */ |
||
| 63 | public $pageInfo; |
||
| 64 | /** |
||
| 65 | * @var MatchStrategy |
||
| 66 | * @JMS\Type("GroupByInc\API\Model\MatchStrategy") |
||
| 67 | */ |
||
| 68 | public $matchStrategy; |
||
| 69 | /** |
||
| 70 | * @var Navigation[] |
||
| 71 | * @JMS\Type("array<GroupByInc\API\Model\Navigation>") |
||
| 72 | */ |
||
| 73 | public $availableNavigation = array(); |
||
| 74 | /** |
||
| 75 | * @var Navigation[] |
||
| 76 | * @JMS\Type("array<GroupByInc\API\Model\Navigation>") |
||
| 77 | */ |
||
| 78 | public $selectedNavigation = array(); |
||
| 79 | /** |
||
| 80 | * @var Record[] |
||
| 81 | * @JMS\Type("array<GroupByInc\API\Model\Record>") |
||
| 82 | */ |
||
| 83 | public $records = array(); |
||
| 84 | /** |
||
| 85 | * @var string[] |
||
| 86 | * @JMS\Type("array<string>") |
||
| 87 | */ |
||
| 88 | public $didYouMean = array(); |
||
| 89 | /** |
||
| 90 | * @var string[] |
||
| 91 | * @JMS\Type("array<string>") |
||
| 92 | */ |
||
| 93 | public $relatedQueries = array(); |
||
| 94 | /** |
||
| 95 | * @var string[] |
||
| 96 | * @JMS\Type("array<string>") |
||
| 97 | */ |
||
| 98 | public $rewrites = array(); |
||
| 99 | /** |
||
| 100 | * @var Metadata[] |
||
| 101 | * @JMS\Type("array<GroupByInc\API\Model\Metadata>") |
||
| 102 | */ |
||
| 103 | public $siteParams = array(); |
||
| 104 | /** |
||
| 105 | * @var string[] |
||
| 106 | * @JMS\Type("array<string>") |
||
| 107 | */ |
||
| 108 | public $warnings = array(); |
||
| 109 | /** |
||
| 110 | * @var ResultsMetadata |
||
| 111 | * @JMS\Type("GroupByInc\API\Model\ResultsMetadata") |
||
| 112 | */ |
||
| 113 | public $resultsMetadata; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @return string The ID of the response. |
||
| 117 | */ |
||
| 118 | public function getId() |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @param string $id Set the response ID. |
||
| 125 | */ |
||
| 126 | public function setId($id) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @return string[] A list of spell corrections based on the search term. |
||
| 133 | */ |
||
| 134 | public function getDidYouMean() |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @param string[] $didYouMean Set the list. |
||
| 141 | */ |
||
| 142 | public function setDidYouMean($didYouMean) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @return string[] A list of related queries for a given search term. |
||
| 149 | */ |
||
| 150 | public function getRelatedQueries() |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param string[] $relatedQueries Set the related queries for a search term. |
||
| 157 | */ |
||
| 158 | public function setRelatedQueries($relatedQueries) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @return Record[] A list of the records for this search and navigation state. |
||
| 165 | */ |
||
| 166 | public function getRecords() |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @param Record[] $records Set the records. |
||
| 173 | */ |
||
| 174 | public function setRecords($records) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @return Template If a rule has fired, the associated template will be returned. |
||
| 181 | */ |
||
| 182 | public function getTemplate() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param Template $template Set the template. |
||
| 189 | */ |
||
| 190 | public function setTemplate($template) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @return PageInfo Information about the results page. |
||
| 197 | */ |
||
| 198 | public function getPageInfo() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @param PageInfo $pageInfo Set the page info. |
||
| 205 | */ |
||
| 206 | public function setPageInfo($pageInfo) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @return MatchStrategy associated with this Results object |
||
| 213 | */ |
||
| 214 | public function getMatchStrategy() |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @param MatchStrategy $matchStrategy Set the match strategy |
||
| 221 | */ |
||
| 222 | public function setMatchStrategy($matchStrategy) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @return Navigation[] A list of all the ways in which you can filter the current result set. |
||
| 229 | */ |
||
| 230 | public function getAvailableNavigation() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @param Navigation[] $availableNavigation Set the available navigation. |
||
| 237 | */ |
||
| 238 | public function setAvailableNavigation($availableNavigation) |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @return Navigation[] A list of the currently selected navigations. Also known as breadcrumbs. |
||
| 245 | */ |
||
| 246 | public function getSelectedNavigation() |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @param Navigation[] $selectedNavigation Set the selected navigations. |
||
| 253 | */ |
||
| 254 | public function setSelectedNavigation($selectedNavigation) |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @return string A URL to redirect to based on this search term. |
||
| 261 | */ |
||
| 262 | public function getRedirect() |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @param string $redirect Set the redirect. |
||
| 269 | */ |
||
| 270 | public function setRedirect($redirect) |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @return string representation of any errors encountered. |
||
| 277 | */ |
||
| 278 | public function getErrors() |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @param string $errors Set errors. |
||
| 285 | */ |
||
| 286 | public function setErrors($errors) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @return int A count of the total number of records in this search and navigation state. |
||
| 293 | */ |
||
| 294 | public function getTotalRecordCount() |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @param int $totalRecordCount Set the total record count. |
||
| 301 | */ |
||
| 302 | public function setTotalRecordCount($totalRecordCount) |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @return Metadata[] A list of metadata as set in the area management section of the command center. |
||
| 309 | */ |
||
| 310 | public function getSiteParams() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * @param Metadata[] $siteParams Set the site metadata. |
||
| 317 | */ |
||
| 318 | public function setSiteParams($siteParams) |
||
| 322 | |||
| 323 | /** |
||
| 324 | * @return string The query sent to the bridge. |
||
| 325 | */ |
||
| 326 | public function getQuery() |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @param string $query Sets the query to the bridge. |
||
| 333 | */ |
||
| 334 | public function setQuery($query) |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @return string The original query sent to the search service. |
||
| 341 | */ |
||
| 342 | public function getOriginalQuery() |
||
| 346 | |||
| 347 | /** |
||
| 348 | * @param string $originalQuery Sets the original query sent to the search service. |
||
| 349 | */ |
||
| 350 | public function setOriginalQuery($originalQuery) |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @return string The corrected query sent to the engine, if auto-correction is enabled. |
||
| 357 | */ |
||
| 358 | public function getCorrectedQuery() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @param string $correctedQuery Sets the corrected query sent to the engine, if auto-correction is enabled. |
||
| 365 | */ |
||
| 366 | public function setCorrectedQuery($correctedQuery) |
||
| 370 | |||
| 371 | /** |
||
| 372 | * @return string[] A list of rewrites (spellings, synonyms, etc...) that occurred. |
||
| 373 | */ |
||
| 374 | public function getRewrites() |
||
| 378 | |||
| 379 | /** |
||
| 380 | * @param string[] $rewrites Sets the rewrites that occurred. |
||
| 381 | */ |
||
| 382 | public function setRewrites($rewrites) |
||
| 386 | |||
| 387 | /** |
||
| 388 | * @return string The area that the search fired against. |
||
| 389 | */ |
||
| 390 | public function getArea() |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @param string $area Sets the area. |
||
| 397 | */ |
||
| 398 | public function setArea($area) |
||
| 402 | |||
| 403 | /** |
||
| 404 | * @return string |
||
| 405 | */ |
||
| 406 | public function getBiasingProfile() |
||
| 410 | |||
| 411 | /** |
||
| 412 | * @param string $biasingProfile |
||
| 413 | */ |
||
| 414 | public function setBiasingProfile($biasingProfile) |
||
| 418 | |||
| 419 | /** |
||
| 420 | * @return string[] |
||
| 421 | */ |
||
| 422 | public function getWarnings() |
||
| 426 | |||
| 427 | /** |
||
| 428 | * @param string[] $warnings |
||
| 429 | */ |
||
| 430 | public function setWarnings($warnings) |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @return ResultsMetadata |
||
| 437 | */ |
||
| 438 | public function getResultsMetadata() |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @param ResultsMetadata $resultsMetadata |
||
| 445 | */ |
||
| 446 | public function setResultsMetadata($resultsMetadata) |
||
| 450 | } |
||
| 451 |