Complex classes like LineItem 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 LineItem, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class LineItem extends Analytics |
||
| 16 | { |
||
| 17 | const RESOURCE_COLLECTION = 'accounts/{account_id}/line_items'; |
||
| 18 | const RESOURCE = 'accounts/{account_id}/line_items/{id}'; |
||
| 19 | |||
| 20 | const ENTITY = "LINE_ITEM"; |
||
| 21 | |||
| 22 | /** Read Only */ |
||
| 23 | protected $id; |
||
| 24 | protected $created_at; |
||
| 25 | protected $updated_at; |
||
| 26 | protected $deleted; |
||
| 27 | |||
| 28 | protected $properties = [ |
||
| 29 | 'campaign_id', |
||
| 30 | 'bid_amount_local_micro', |
||
| 31 | 'name', |
||
| 32 | 'bid_type', |
||
| 33 | 'automatically_select_bid', |
||
| 34 | 'product_type', |
||
| 35 | 'placements', |
||
| 36 | 'objective', |
||
| 37 | 'paused', |
||
| 38 | 'include_sentiment', |
||
| 39 | 'total_budget_amount_local_micro', |
||
| 40 | 'start_time', |
||
| 41 | 'end_time', |
||
| 42 | 'primary_web_event_tag', |
||
| 43 | 'optimization', |
||
| 44 | 'bid_unit', |
||
| 45 | 'charge_by', |
||
| 46 | 'advertiser_domain', |
||
| 47 | 'advertiser_user_id', |
||
| 48 | ]; |
||
| 49 | |||
| 50 | /** Writable */ |
||
| 51 | protected $campaign_id; |
||
| 52 | protected $bid_amount_local_micro; |
||
| 53 | protected $name; |
||
| 54 | protected $bid_type; |
||
| 55 | protected $automatically_select_bid; |
||
| 56 | protected $product_type; |
||
| 57 | protected $placements; |
||
| 58 | protected $objective; |
||
| 59 | protected $paused; |
||
| 60 | protected $include_sentiment; |
||
| 61 | protected $total_budget_amount_local_micro; |
||
| 62 | protected $start_time; |
||
| 63 | protected $end_time; |
||
| 64 | protected $primary_web_event_tag; |
||
| 65 | protected $optimization; |
||
| 66 | protected $bid_unit; |
||
| 67 | protected $charge_by; |
||
| 68 | protected $advertiser_domain; |
||
| 69 | protected $tracking_tags; |
||
| 70 | protected $advertiser_user_id; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Returns a collection of targeting criteria available to the |
||
| 74 | * current line item. |
||
| 75 | * |
||
| 76 | * @param string $id |
||
| 77 | * @param array $params |
||
| 78 | * |
||
| 79 | * @return Cursor | Resource |
||
| 80 | * |
||
| 81 | * @throws TwitterAdsException |
||
| 82 | */ |
||
| 83 | public function getTargetingCriteria($id = '', $params = []) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @return mixed |
||
| 100 | */ |
||
| 101 | public function getId() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @return mixed |
||
| 108 | */ |
||
| 109 | public function getCreatedAt() |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @return mixed |
||
| 116 | */ |
||
| 117 | public function getUpdatedAt() |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @return mixed |
||
| 124 | */ |
||
| 125 | public function getDeleted() |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @return array |
||
| 132 | */ |
||
| 133 | public function getProperties() |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @param array $properties |
||
| 140 | */ |
||
| 141 | public function setProperties($properties) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @return mixed |
||
| 148 | */ |
||
| 149 | public function getCampaignId() |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param mixed $campaign_id |
||
| 156 | */ |
||
| 157 | public function setCampaignId($campaign_id) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @return mixed |
||
| 164 | */ |
||
| 165 | public function getBidAmountLocalMicro() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @param mixed $bid_amount_local_micro |
||
| 172 | */ |
||
| 173 | public function setBidAmountLocalMicro($bid_amount_local_micro) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @return mixed |
||
| 180 | */ |
||
| 181 | public function getName() |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @param mixed $name |
||
| 188 | */ |
||
| 189 | public function setName($name) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @return mixed |
||
| 196 | */ |
||
| 197 | public function getBidType() |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param mixed $bid_type |
||
| 204 | */ |
||
| 205 | public function setBidType($bid_type) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @return mixed |
||
| 212 | */ |
||
| 213 | public function getAutomaticallySelectdBid() |
||
| 214 | { |
||
| 215 | return $this->automatically_select_bid; |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param mixed $automatically_select_bid |
||
| 220 | */ |
||
| 221 | public function setAutomaticallySelectBid($automatically_select_bid) |
||
| 222 | { |
||
| 223 | $this->automatically_select_bid = $automatically_select_bid; |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @return mixed |
||
| 228 | */ |
||
| 229 | public function getProductType() |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @param mixed $product_type |
||
| 236 | */ |
||
| 237 | public function setProductType($product_type) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @return mixed |
||
| 244 | */ |
||
| 245 | public function getPlacements() |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @param mixed $placements |
||
| 252 | */ |
||
| 253 | public function setPlacements($placements) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @return mixed |
||
| 260 | */ |
||
| 261 | public function getObjective() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @param mixed $objective |
||
| 268 | */ |
||
| 269 | public function setObjective($objective) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @return mixed |
||
| 276 | */ |
||
| 277 | public function getPaused() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @param mixed $paused |
||
| 284 | */ |
||
| 285 | public function setPaused($paused) |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @return mixed |
||
| 292 | */ |
||
| 293 | public function getIncludeSentiment() |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @param mixed $include_sentiment |
||
| 300 | */ |
||
| 301 | public function setIncludeSentiment($include_sentiment) |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @return mixed |
||
| 308 | */ |
||
| 309 | public function getTotalBudgetAmountLocalMicro() |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @param mixed $total_budget_amount_local_micro |
||
| 316 | */ |
||
| 317 | public function setTotalBudgetAmountLocalMicro($total_budget_amount_local_micro) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @return mixed |
||
| 324 | */ |
||
| 325 | public function getStartTime() |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @param mixed $start_time |
||
| 332 | */ |
||
| 333 | public function setStartTime($start_time) |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @return mixed |
||
| 340 | */ |
||
| 341 | public function getEndTime() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @param mixed $end_time |
||
| 348 | */ |
||
| 349 | public function setEndTime($end_time) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @return mixed |
||
| 356 | */ |
||
| 357 | public function getPrimaryWebEventTag() |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @param mixed $primary_web_event_tag |
||
| 364 | */ |
||
| 365 | public function setPrimaryWebEventTag($primary_web_event_tag) |
||
| 369 | |||
| 370 | /** |
||
| 371 | * @return mixed |
||
| 372 | */ |
||
| 373 | public function getOptimization() |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @param mixed $optimization |
||
| 380 | */ |
||
| 381 | public function setOptimization($optimization) |
||
| 385 | |||
| 386 | /** |
||
| 387 | * @return mixed |
||
| 388 | */ |
||
| 389 | public function getBidUnit() |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @param mixed $bid_unit |
||
| 396 | */ |
||
| 397 | public function setBidUnit($bid_unit) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * @return mixed |
||
| 404 | */ |
||
| 405 | public function getChargeBy() |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @param mixed $charge_by |
||
| 412 | */ |
||
| 413 | public function setChargeBy($charge_by) |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @return mixed |
||
| 420 | */ |
||
| 421 | public function getAdvertiserDomain() |
||
| 425 | |||
| 426 | /** |
||
| 427 | * @param mixed $advertiser_domain |
||
| 428 | */ |
||
| 429 | public function setAdvertiserDomain($advertiser_domain) |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @return mixed |
||
| 436 | */ |
||
| 437 | public function getTrackingTags() |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @param mixed $tracking_tags |
||
| 444 | */ |
||
| 445 | public function setTrackingTags($tracking_tags) |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @return mixed |
||
| 452 | */ |
||
| 453 | public function getAdvertiserUserId() |
||
| 457 | |||
| 458 | /** |
||
| 459 | * @param mixed $advertiser_user_id |
||
| 460 | */ |
||
| 461 | public function setAdvertiserUserId($advertiser_user_id) |
||
| 465 | } |
||
| 466 |