Complex classes like Item 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 Item, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 38 | class Item |
||
| 39 | { |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The item's uid in the index queue (tx_solr_indexqueue_item.uid) |
||
| 43 | * |
||
| 44 | * @var int |
||
| 45 | */ |
||
| 46 | protected $indexQueueUid; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The root page uid of the tree the item is located in (tx_solr_indexqueue_item.root) |
||
| 50 | * |
||
| 51 | * @var int |
||
| 52 | */ |
||
| 53 | protected $rootPageUid; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * The record's type, usually a table name, but could also be a file type (tx_solr_indexqueue_item.item_type) |
||
| 57 | * |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | protected $type; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * The name of the indexing configuration that should be used when indexing (tx_solr_indexqueue_item.indexing_configuration) |
||
| 64 | * the item. |
||
| 65 | * |
||
| 66 | * @var string |
||
| 67 | */ |
||
| 68 | protected $indexingConfigurationName; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * The unix timestamp when the record was last changed (tx_solr_indexqueue_item.changed) |
||
| 72 | * |
||
| 73 | * @var int |
||
| 74 | */ |
||
| 75 | protected $changed; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Indexing properties to provide additional information for the item's |
||
| 79 | * indexer / how to index the item. |
||
| 80 | * |
||
| 81 | * @var array |
||
| 82 | */ |
||
| 83 | protected $indexingProperties = []; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Flag for lazy loading indexing properties. |
||
| 87 | * |
||
| 88 | * @var bool |
||
| 89 | */ |
||
| 90 | protected $indexingPropertiesLoaded = false; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Flag, whether indexing properties exits for this item. |
||
| 94 | * |
||
| 95 | * @var bool |
||
| 96 | */ |
||
| 97 | protected $hasIndexingProperties = false; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * The record's uid. |
||
| 101 | * |
||
| 102 | * @var int |
||
| 103 | */ |
||
| 104 | protected $recordUid = 0; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * The record itself |
||
| 108 | * |
||
| 109 | * @var array |
||
| 110 | */ |
||
| 111 | protected $record; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Moint point identifier. |
||
| 115 | * |
||
| 116 | * @var string |
||
| 117 | */ |
||
| 118 | protected $mountPointIdentifier; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @var string |
||
| 122 | */ |
||
| 123 | protected $errors = ''; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Constructor, takes item meta data information and resolves that to the full record. |
||
| 127 | * |
||
| 128 | * @param array $itemMetaData Metadata describing the item to index using the index queue. Is expected to contain a record from table tx_solr_indexqueue_item |
||
| 129 | * @param array $fullRecord Optional full record for the item. If provided, can save some SQL queries. |
||
| 130 | */ |
||
| 131 | 58 | public function __construct( |
|
| 150 | |||
| 151 | /** |
||
| 152 | * @return int|mixed |
||
| 153 | */ |
||
| 154 | 8 | public function getIndexQueueUid() |
|
| 158 | |||
| 159 | /** |
||
| 160 | * Gets the item's root page ID (uid) |
||
| 161 | * |
||
| 162 | * @return int root page ID |
||
| 163 | */ |
||
| 164 | 21 | public function getRootPageUid() |
|
| 168 | |||
| 169 | /** |
||
| 170 | * Returns mount point identifier |
||
| 171 | * |
||
| 172 | * @return string |
||
| 173 | */ |
||
| 174 | 16 | public function getMountPointIdentifier() |
|
| 178 | |||
| 179 | /** |
||
| 180 | * @param integer $uid |
||
| 181 | */ |
||
| 182 | public function setRootPageUid($uid) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @return string |
||
| 189 | */ |
||
| 190 | 5 | public function getErrors() |
|
| 194 | |||
| 195 | /** |
||
| 196 | * Gets the site the item belongs to. |
||
| 197 | * |
||
| 198 | * @return Site Site instance the item belongs to. |
||
| 199 | */ |
||
| 200 | 22 | public function getSite() |
|
| 205 | |||
| 206 | 18 | public function getType() |
|
| 210 | |||
| 211 | public function setType($type) |
||
| 215 | |||
| 216 | 27 | public function getIndexingConfigurationName() |
|
| 220 | |||
| 221 | public function setIndexingConfigurationName($indexingConfigurationName) |
||
| 225 | |||
| 226 | public function getChanged() |
||
| 230 | |||
| 231 | public function setChanged($changed) |
||
| 235 | |||
| 236 | 4 | public function getRecordUid() |
|
| 242 | |||
| 243 | /** |
||
| 244 | * Gets the item's full record. |
||
| 245 | * |
||
| 246 | * Uses lazy loading. |
||
| 247 | * |
||
| 248 | * @return array The item's DB record. |
||
| 249 | */ |
||
| 250 | 15 | public function getRecord() |
|
| 264 | |||
| 265 | public function setRecord(array $record) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @return int |
||
| 272 | */ |
||
| 273 | 13 | public function getRecordPageId() |
|
| 279 | |||
| 280 | /** |
||
| 281 | * Stores the indexing properties. |
||
| 282 | * |
||
| 283 | */ |
||
| 284 | 7 | public function storeIndexingProperties() |
|
| 294 | |||
| 295 | /** |
||
| 296 | * Removes existing indexing properties. |
||
| 297 | * |
||
| 298 | * @throws \RuntimeException when an SQL error occurs |
||
| 299 | */ |
||
| 300 | 7 | protected function removeIndexingProperties() |
|
| 315 | |||
| 316 | 7 | public function hasIndexingProperties() |
|
| 320 | |||
| 321 | /** |
||
| 322 | * Writes all indexing properties. |
||
| 323 | * |
||
| 324 | * @throws \RuntimeException when an SQL error occurs |
||
| 325 | */ |
||
| 326 | 7 | protected function writeIndexingProperties() |
|
| 351 | |||
| 352 | /** |
||
| 353 | * Updates the "has_indexing_properties" flag in the Index Queue. |
||
| 354 | * |
||
| 355 | * @throws \RuntimeException when an SQL error occurs |
||
| 356 | */ |
||
| 357 | 7 | protected function updateHasIndexingPropertiesFlag() |
|
| 377 | |||
| 378 | /** |
||
| 379 | * @param string $key |
||
| 380 | * @return bool |
||
| 381 | */ |
||
| 382 | 1 | public function hasIndexingProperty($key) |
|
| 388 | |||
| 389 | /** |
||
| 390 | * Loads the indexing properties for the item - if not already loaded. |
||
| 391 | * |
||
| 392 | */ |
||
| 393 | 8 | public function loadIndexingProperties() |
|
| 411 | |||
| 412 | /** |
||
| 413 | * Sets an indexing property for the item. |
||
| 414 | * |
||
| 415 | * @param string $key Indexing property name |
||
| 416 | * @param string|int|float $value Indexing property value |
||
| 417 | * @throws \InvalidArgumentException when $value is not string, integer or float |
||
| 418 | */ |
||
| 419 | 7 | public function setIndexingProperty($key, $value) |
|
| 439 | |||
| 440 | /** |
||
| 441 | * Gets a specific indexing property by its name/key. |
||
| 442 | * |
||
| 443 | * @param string $key Indexing property name/key. |
||
| 444 | * @throws \InvalidArgumentException when the given $key does not exist. |
||
| 445 | * @return string |
||
| 446 | */ |
||
| 447 | public function getIndexingProperty($key) |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Gets all indexing properties set for this item. |
||
| 463 | * |
||
| 464 | * @return array Array of indexing properties. |
||
| 465 | */ |
||
| 466 | public function getIndexingProperties() |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Gets the names/keys of the item's indexing properties. |
||
| 475 | * |
||
| 476 | * @return array Array of indexing property names/keys |
||
| 477 | */ |
||
| 478 | public function getIndexingPropertyKeys() |
||
| 484 | } |
||
| 485 |