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 | /** |
||
| 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 Navigation[] |
||
| 67 | * @JMS\Type("array<GroupByInc\API\Model\Navigation>") |
||
| 68 | */ |
||
| 69 | public $availableNavigation = array(); |
||
| 70 | /** |
||
| 71 | * @var Navigation[] |
||
| 72 | * @JMS\Type("array<GroupByInc\API\Model\Navigation>") |
||
| 73 | */ |
||
| 74 | public $selectedNavigation = array(); |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var Record[] |
||
| 78 | * @JMS\Type("array<GroupByInc\API\Model\Record>") |
||
| 79 | */ |
||
| 80 | public $records = array(); |
||
| 81 | /** |
||
| 82 | * @var string[] |
||
| 83 | * @JMS\Type("array<string>") |
||
| 84 | */ |
||
| 85 | public $didYouMean = array(); |
||
| 86 | /** |
||
| 87 | * @var string[] |
||
| 88 | * @JMS\Type("array<string>") |
||
| 89 | */ |
||
| 90 | public $relatedQueries = array(); |
||
| 91 | /** |
||
| 92 | * @var string[] |
||
| 93 | * @JMS\Type("array<string>") |
||
| 94 | */ |
||
| 95 | public $rewrites = array(); |
||
| 96 | /** |
||
| 97 | * @var Metadata[] |
||
| 98 | * @JMS\Type("array<GroupByInc\API\Model\Metadata>") |
||
| 99 | */ |
||
| 100 | public $siteParams = array(); |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @var string[] |
||
| 104 | * @JMS\Type("array<string>") |
||
| 105 | */ |
||
| 106 | public $warnings = array(); |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var ResultsMetadata |
||
| 110 | * @JMS\Type("GroupByInc\API\Model\ResultsMetadata") |
||
| 111 | */ |
||
| 112 | public $resultsMetadata; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @return string The ID of the response. |
||
| 116 | */ |
||
| 117 | public function getId() |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @param string $id Set the response ID. |
||
| 124 | */ |
||
| 125 | public function setId($id) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @return string[] A list of spell corrections based on the search term. |
||
| 132 | */ |
||
| 133 | public function getDidYouMean() |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @param string[] $didYouMean Set the list. |
||
| 140 | */ |
||
| 141 | public function setDidYouMean($didYouMean) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @return string[] A list of related queries for a given search term. |
||
| 148 | */ |
||
| 149 | public function getRelatedQueries() |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param string[] $relatedQueries Set the related queries for a search term. |
||
| 156 | */ |
||
| 157 | public function setRelatedQueries($relatedQueries) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @return Record[] A list of the records for this search and navigation state. |
||
| 164 | */ |
||
| 165 | public function getRecords() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @param Record[] $records Set the records. |
||
| 172 | */ |
||
| 173 | public function setRecords($records) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @return Template If a rule has fired, the associated template will be returned. |
||
| 180 | */ |
||
| 181 | public function getTemplate() |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @param Template $template Set the template. |
||
| 188 | */ |
||
| 189 | public function setTemplate($template) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @return PageInfo Information about the results page. |
||
| 196 | */ |
||
| 197 | public function getPageInfo() |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param PageInfo $pageInfo Set the page info. |
||
| 204 | */ |
||
| 205 | public function setPageInfo($pageInfo) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @return Navigation[] A list of all the ways in which you can filter the current result set. |
||
| 212 | */ |
||
| 213 | public function getAvailableNavigation() |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param Navigation[] $availableNavigation Set the available navigation. |
||
| 220 | */ |
||
| 221 | public function setAvailableNavigation($availableNavigation) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @return Navigation[] A list of the currently selected navigations. Also known as breadcrumbs. |
||
| 228 | */ |
||
| 229 | public function getSelectedNavigation() |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @param Navigation[] $selectedNavigation Set the selected navigations. |
||
| 236 | */ |
||
| 237 | public function setSelectedNavigation($selectedNavigation) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @return string A URL to redirect to based on this search term. |
||
| 244 | */ |
||
| 245 | public function getRedirect() |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @param string $redirect Set the redirect. |
||
| 252 | */ |
||
| 253 | public function setRedirect($redirect) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @return string representation of any errors encountered. |
||
| 260 | */ |
||
| 261 | public function getErrors() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @param string $errors Set errors. |
||
| 268 | */ |
||
| 269 | public function setErrors($errors) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @return int A count of the total number of records in this search and navigation state. |
||
| 276 | */ |
||
| 277 | public function getTotalRecordCount() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @param int $totalRecordCount Set the total record count. |
||
| 284 | */ |
||
| 285 | public function setTotalRecordCount($totalRecordCount) |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @return Metadata[] A list of metadata as set in the area management section of the command center. |
||
| 292 | */ |
||
| 293 | public function getSiteParams() |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @param Metadata[] $siteParams Set the site metadata. |
||
| 300 | */ |
||
| 301 | public function setSiteParams($siteParams) |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @return string The query sent to the bridge. |
||
| 308 | */ |
||
| 309 | public function getQuery() |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @param string $query Sets the query to the bridge. |
||
| 316 | */ |
||
| 317 | public function setQuery($query) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @return string The original query sent to the search service. |
||
| 324 | */ |
||
| 325 | public function getOriginalQuery() |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @param string $originalQuery Sets the original query sent to the search service. |
||
| 332 | */ |
||
| 333 | public function setOriginalQuery($originalQuery) |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @return string The corrected query sent to the engine, if auto-correction is enabled. |
||
| 340 | */ |
||
| 341 | public function getCorrectedQuery() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @param string $correctedQuery Sets the corrected query sent to the engine, if auto-correction is enabled. |
||
| 348 | */ |
||
| 349 | public function setCorrectedQuery($correctedQuery) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @return string[] A list of rewrites (spellings, synonyms, etc...) that occurred. |
||
| 356 | */ |
||
| 357 | public function getRewrites() |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @param string[] $rewrites Sets the rewrites that occurred. |
||
| 364 | */ |
||
| 365 | public function setRewrites($rewrites) |
||
| 369 | |||
| 370 | /** |
||
| 371 | * @return string The area that the search fired against. |
||
| 372 | */ |
||
| 373 | public function getArea() |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @param string $area Sets the area. |
||
| 380 | */ |
||
| 381 | public function setArea($area) |
||
| 385 | |||
| 386 | /** |
||
| 387 | * @return string |
||
| 388 | */ |
||
| 389 | public function getBiasingProfile() |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @param string $biasingProfile |
||
| 396 | */ |
||
| 397 | public function setBiasingProfile($biasingProfile) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * @return string[] |
||
| 404 | */ |
||
| 405 | public function getWarnings() |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @param string[] $warnings |
||
| 412 | */ |
||
| 413 | public function setWarnings($warnings) |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @return ResultsMetadata |
||
| 420 | */ |
||
| 421 | public function getResultsMetadata() |
||
| 425 | |||
| 426 | /** |
||
| 427 | * @param ResultsMetadata $resultsMetadata |
||
| 428 | */ |
||
| 429 | public function setResultsMetadata($resultsMetadata) |
||
| 433 | } |
||
| 434 |