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 string[] |
||
| 97 | * @JMS\Type("array<string>") |
||
| 98 | */ |
||
| 99 | public $rewrites = array(); |
||
| 100 | /** |
||
| 101 | * @var Metadata[] |
||
| 102 | * @JMS\Type("array<GroupByInc\API\Model\Metadata>") |
||
| 103 | */ |
||
| 104 | public $siteParams = array(); |
||
| 105 | /** |
||
| 106 | * @var string[] |
||
| 107 | * @JMS\Type("array<string>") |
||
| 108 | */ |
||
| 109 | public $warnings = array(); |
||
| 110 | /** |
||
| 111 | * @var ResultsMetadata |
||
| 112 | * @JMS\Type("GroupByInc\API\Model\ResultsMetadata") |
||
| 113 | */ |
||
| 114 | public $resultsMetadata; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @return string The ID of the response. |
||
| 118 | */ |
||
| 119 | public function getId() |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @param string $id Set the response ID. |
||
| 126 | */ |
||
| 127 | public function setId($id) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @return string[] A list of spell corrections based on the search term. |
||
| 134 | */ |
||
| 135 | public function getDidYouMean() |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @param string[] $didYouMean Set the list. |
||
| 142 | */ |
||
| 143 | public function setDidYouMean($didYouMean) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @return string[] A list of related queries for a given search term. |
||
| 150 | */ |
||
| 151 | public function getRelatedQueries() |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param string[] $relatedQueries Set the related queries for a search term. |
||
| 158 | */ |
||
| 159 | public function setRelatedQueries($relatedQueries) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @return Record[] A list of the records for this search and navigation state. |
||
| 166 | */ |
||
| 167 | public function getRecords() |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @param Record[] $records Set the records. |
||
| 174 | */ |
||
| 175 | public function setRecords($records) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @return Template If a rule has fired, the associated template will be returned. |
||
| 182 | */ |
||
| 183 | public function getTemplate() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @param Template $template Set the template. |
||
| 190 | */ |
||
| 191 | public function setTemplate($template) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @return PageInfo Information about the results page. |
||
| 198 | */ |
||
| 199 | public function getPageInfo() |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @param PageInfo $pageInfo Set the page info. |
||
| 206 | */ |
||
| 207 | public function setPageInfo($pageInfo) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @return MatchStrategy associated with this Results object |
||
| 214 | */ |
||
| 215 | public function getMatchStrategy() |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @param MatchStrategy $matchStrategy Set the match strategy |
||
| 222 | */ |
||
| 223 | public function setMatchStrategy($matchStrategy) |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @return Navigation[] A list of all the ways in which you can filter the current result set. |
||
| 230 | */ |
||
| 231 | public function getAvailableNavigation() |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @param Navigation[] $availableNavigation Set the available navigation. |
||
| 238 | */ |
||
| 239 | public function setAvailableNavigation($availableNavigation) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @return Navigation[] A list of the currently selected navigations. Also known as breadcrumbs. |
||
| 246 | */ |
||
| 247 | public function getSelectedNavigation() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @param Navigation[] $selectedNavigation Set the selected navigations. |
||
| 254 | */ |
||
| 255 | public function setSelectedNavigation($selectedNavigation) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @return string A URL to redirect to based on this search term. |
||
| 262 | */ |
||
| 263 | public function getRedirect() |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @param string $redirect Set the redirect. |
||
| 270 | */ |
||
| 271 | public function setRedirect($redirect) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @return string representation of any errors encountered. |
||
| 278 | */ |
||
| 279 | public function getErrors() |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @param string $errors Set errors. |
||
| 286 | */ |
||
| 287 | public function setErrors($errors) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @return int A count of the total number of records in this search and navigation state. |
||
| 294 | */ |
||
| 295 | public function getTotalRecordCount() |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @param int $totalRecordCount Set the total record count. |
||
| 302 | */ |
||
| 303 | public function setTotalRecordCount($totalRecordCount) |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @return Metadata[] A list of metadata as set in the area management section of the command center. |
||
| 310 | */ |
||
| 311 | public function getSiteParams() |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @param Metadata[] $siteParams Set the site metadata. |
||
| 318 | */ |
||
| 319 | public function setSiteParams($siteParams) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @return string The query sent to the bridge. |
||
| 326 | */ |
||
| 327 | public function getQuery() |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @param string $query Sets the query to the bridge. |
||
| 334 | */ |
||
| 335 | public function setQuery($query) |
||
| 339 | |||
| 340 | /** |
||
| 341 | * @return string The original query sent to the search service. |
||
| 342 | */ |
||
| 343 | public function getOriginalQuery() |
||
| 347 | |||
| 348 | /** |
||
| 349 | * @param string $originalQuery Sets the original query sent to the search service. |
||
| 350 | */ |
||
| 351 | public function setOriginalQuery($originalQuery) |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @return string The corrected query sent to the engine, if auto-correction is enabled. |
||
| 358 | */ |
||
| 359 | public function getCorrectedQuery() |
||
| 363 | |||
| 364 | /** |
||
| 365 | * @param string $correctedQuery Sets the corrected query sent to the engine, if auto-correction is enabled. |
||
| 366 | */ |
||
| 367 | public function setCorrectedQuery($correctedQuery) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @return string[] A list of rewrites (spellings, synonyms, etc...) that occurred. |
||
| 374 | */ |
||
| 375 | public function getRewrites() |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @param string[] $rewrites Sets the rewrites that occurred. |
||
| 382 | */ |
||
| 383 | public function setRewrites($rewrites) |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @return string The area that the search fired against. |
||
| 390 | */ |
||
| 391 | public function getArea() |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @param string $area Sets the area. |
||
| 398 | */ |
||
| 399 | public function setArea($area) |
||
| 403 | |||
| 404 | /** |
||
| 405 | * @return string |
||
| 406 | */ |
||
| 407 | public function getBiasingProfile() |
||
| 411 | |||
| 412 | /** |
||
| 413 | * @param string $biasingProfile |
||
| 414 | */ |
||
| 415 | public function setBiasingProfile($biasingProfile) |
||
| 419 | |||
| 420 | /** |
||
| 421 | * @return string[] |
||
| 422 | */ |
||
| 423 | public function getWarnings() |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @param string[] $warnings |
||
| 430 | */ |
||
| 431 | public function setWarnings($warnings) |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @return ResultsMetadata |
||
| 438 | */ |
||
| 439 | public function getResultsMetadata() |
||
| 443 | |||
| 444 | /** |
||
| 445 | * @param ResultsMetadata $resultsMetadata |
||
| 446 | */ |
||
| 447 | public function setResultsMetadata($resultsMetadata) |
||
| 451 | } |
||
| 452 |