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 |
||
| 13 | class LineItem extends Analytics |
||
| 14 | { |
||
| 15 | const RESOURCE_COLLECTION = 'accounts/{account_id}/line_items'; |
||
| 16 | const RESOURCE = 'accounts/{account_id}/line_items/{id}'; |
||
| 17 | |||
| 18 | const ENTITY = "LINE_ITEM"; |
||
| 19 | |||
| 20 | /** Read Only */ |
||
| 21 | protected $id; |
||
| 22 | protected $created_at; |
||
| 23 | protected $updated_at; |
||
| 24 | protected $deleted; |
||
| 25 | protected $target_cpa_local_micro; |
||
| 26 | protected $currency; |
||
| 27 | |||
| 28 | protected $properties = [ |
||
| 29 | LineItemFields::CAMPAIGN_ID, |
||
| 30 | LineItemFields::BID_AMOUNT_LOCAL_MICRO, |
||
| 31 | LineItemFields::NAME, |
||
| 32 | LineItemFields::BID_TYPE, |
||
| 33 | LineItemFields::AUTOMATICALLY_SELECT_BID, |
||
| 34 | LineItemFields::PRODUCT_TYPE, |
||
| 35 | LineItemFields::PLACEMENTS, |
||
| 36 | LineItemFields::OBJECTIVE, |
||
| 37 | LineItemFields::ENTITY_STATUS, |
||
| 38 | LineItemFields::INCLUDE_SENTIMENT, |
||
| 39 | LineItemFields::TOTAL_BUDGET_AMOUNT_LOCAL_MICRO, |
||
| 40 | LineItemFields::START_TIME, |
||
| 41 | LineItemFields::END_TIME, |
||
| 42 | LineItemFields::PRIMARY_WEB_EVENT_TAG, |
||
| 43 | LineItemFields::OPTIMIZATION, |
||
| 44 | LineItemFields::BID_UNIT, |
||
| 45 | LineItemFields::CHARGE_BY, |
||
| 46 | LineItemFields::ADVERTISER_DOMAIN, |
||
| 47 | LineItemFields::ADVERTISER_USER_ID, |
||
| 48 | LineItemFields::CATEGORIES |
||
| 49 | ]; |
||
| 50 | |||
| 51 | /** Writable */ |
||
| 52 | protected $campaign_id; |
||
| 53 | protected $bid_amount_local_micro; |
||
| 54 | protected $name; |
||
| 55 | protected $bid_type; |
||
| 56 | protected $automatically_select_bid; |
||
| 57 | protected $product_type; |
||
| 58 | protected $placements; |
||
| 59 | protected $objective; |
||
| 60 | protected $entity_status; |
||
| 61 | protected $include_sentiment; |
||
| 62 | protected $total_budget_amount_local_micro; |
||
| 63 | protected $start_time; |
||
| 64 | protected $end_time; |
||
| 65 | protected $primary_web_event_tag; |
||
| 66 | protected $optimization; |
||
| 67 | protected $bid_unit; |
||
| 68 | protected $charge_by; |
||
| 69 | protected $advertiser_domain; |
||
| 70 | protected $tracking_tags; |
||
| 71 | protected $advertiser_user_id; |
||
| 72 | protected $categories; |
||
| 73 | |||
| 74 | public function getPromotedTweets($params = []) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @param $metricGroups |
||
| 83 | * @param array $params |
||
| 84 | * @param bool $async |
||
| 85 | * @return Job| mixed |
||
| 86 | */ |
||
| 87 | public function stats($metricGroups, $params = [], $async = false) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Returns a collection of targeting criteria available to the |
||
| 95 | * current line item. |
||
| 96 | * |
||
| 97 | * @param string $id |
||
| 98 | * @param array $params |
||
| 99 | * |
||
| 100 | * @return Cursor | Resource |
||
| 101 | * |
||
| 102 | * @throws TwitterAdsException |
||
| 103 | */ |
||
| 104 | public function getTargetingCriteria($id = '', $params = []) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @return mixed |
||
| 120 | */ |
||
| 121 | public function getId() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @return mixed |
||
| 128 | */ |
||
| 129 | public function getCreatedAt() |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @return mixed |
||
| 136 | */ |
||
| 137 | public function getUpdatedAt() |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @return mixed |
||
| 144 | */ |
||
| 145 | public function getDeleted() |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @return array |
||
| 152 | */ |
||
| 153 | public function getProperties() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @param array $properties |
||
| 160 | */ |
||
| 161 | public function setProperties($properties) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @return mixed |
||
| 168 | */ |
||
| 169 | public function getCampaignId() |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @param mixed $campaign_id |
||
| 176 | */ |
||
| 177 | public function setCampaignId($campaign_id) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @return mixed |
||
| 184 | */ |
||
| 185 | public function getBidAmountLocalMicro() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @param mixed $bid_amount_local_micro |
||
| 192 | */ |
||
| 193 | public function setBidAmountLocalMicro($bid_amount_local_micro) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @return mixed |
||
| 200 | */ |
||
| 201 | public function getName() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @param mixed $name |
||
| 208 | */ |
||
| 209 | public function setName($name) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @return mixed |
||
| 216 | */ |
||
| 217 | public function getBidType() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @param mixed $bid_type |
||
| 224 | */ |
||
| 225 | public function setBidType($bid_type) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @return mixed |
||
| 232 | */ |
||
| 233 | public function getAutomaticallySelectdBid() |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @param mixed $automatically_select_bid |
||
| 240 | */ |
||
| 241 | public function setAutomaticallySelectBid($automatically_select_bid) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @return mixed |
||
| 248 | */ |
||
| 249 | public function getProductType() |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @param mixed $product_type |
||
| 256 | */ |
||
| 257 | public function setProductType($product_type) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @return mixed |
||
| 264 | */ |
||
| 265 | public function getPlacements() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @param mixed $placements |
||
| 272 | */ |
||
| 273 | public function setPlacements($placements) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @return mixed |
||
| 280 | */ |
||
| 281 | public function getObjective() |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @param mixed $objective |
||
| 288 | */ |
||
| 289 | public function setObjective($objective) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @return mixed |
||
| 296 | */ |
||
| 297 | public function getEntityStatus() |
||
| 298 | { |
||
| 299 | return $this->entity_status; |
||
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @param mixed $entity_status |
||
| 304 | */ |
||
| 305 | public function setEntityStatus($entity_status) |
||
| 306 | { |
||
| 307 | $this->entity_status = $entity_status; |
||
| 308 | } |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @return mixed |
||
| 312 | */ |
||
| 313 | public function getIncludeSentiment() |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @param mixed $include_sentiment |
||
| 320 | */ |
||
| 321 | public function setIncludeSentiment($include_sentiment) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * @return mixed |
||
| 328 | */ |
||
| 329 | public function getTotalBudgetAmountLocalMicro() |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @param mixed $total_budget_amount_local_micro |
||
| 336 | */ |
||
| 337 | public function setTotalBudgetAmountLocalMicro($total_budget_amount_local_micro) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @return mixed |
||
| 344 | */ |
||
| 345 | public function getStartTime() |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @param mixed $start_time |
||
| 352 | */ |
||
| 353 | public function setStartTime($start_time) |
||
| 357 | |||
| 358 | /** |
||
| 359 | * @return mixed |
||
| 360 | */ |
||
| 361 | public function getEndTime() |
||
| 365 | |||
| 366 | /** |
||
| 367 | * @param mixed $end_time |
||
| 368 | */ |
||
| 369 | public function setEndTime($end_time) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @return mixed |
||
| 376 | */ |
||
| 377 | public function getPrimaryWebEventTag() |
||
| 381 | |||
| 382 | /** |
||
| 383 | * @param mixed $primary_web_event_tag |
||
| 384 | */ |
||
| 385 | public function setPrimaryWebEventTag($primary_web_event_tag) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @return mixed |
||
| 392 | */ |
||
| 393 | public function getOptimization() |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @param mixed $optimization |
||
| 400 | */ |
||
| 401 | public function setOptimization($optimization) |
||
| 405 | |||
| 406 | /** |
||
| 407 | * @return mixed |
||
| 408 | */ |
||
| 409 | public function getBidUnit() |
||
| 413 | |||
| 414 | /** |
||
| 415 | * @param mixed $bid_unit |
||
| 416 | */ |
||
| 417 | public function setBidUnit($bid_unit) |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @return mixed |
||
| 424 | */ |
||
| 425 | public function getChargeBy() |
||
| 429 | |||
| 430 | /** |
||
| 431 | * @param mixed $charge_by |
||
| 432 | */ |
||
| 433 | public function setChargeBy($charge_by) |
||
| 437 | |||
| 438 | /** |
||
| 439 | * @return mixed |
||
| 440 | */ |
||
| 441 | public function getAdvertiserDomain() |
||
| 445 | |||
| 446 | /** |
||
| 447 | * @param mixed $advertiser_domain |
||
| 448 | */ |
||
| 449 | public function setAdvertiserDomain($advertiser_domain) |
||
| 453 | |||
| 454 | /** |
||
| 455 | * @return mixed |
||
| 456 | */ |
||
| 457 | public function getTrackingTags() |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @param mixed $tracking_tags |
||
| 464 | */ |
||
| 465 | public function setTrackingTags($tracking_tags) |
||
| 469 | |||
| 470 | /** |
||
| 471 | * @return mixed |
||
| 472 | */ |
||
| 473 | public function getAdvertiserUserId() |
||
| 477 | |||
| 478 | /** |
||
| 479 | * @param mixed $advertiser_user_id |
||
| 480 | */ |
||
| 481 | public function setAdvertiserUserId($advertiser_user_id) |
||
| 485 | |||
| 486 | /** |
||
| 487 | * @return mixed |
||
| 488 | */ |
||
| 489 | public function getTargetCpaLocalMicro() |
||
| 493 | |||
| 494 | /** |
||
| 495 | * @return mixed |
||
| 496 | */ |
||
| 497 | public function getAutomaticallySelectBid() |
||
| 501 | |||
| 502 | /** |
||
| 503 | * @return mixed |
||
| 504 | */ |
||
| 505 | public function getCategories() |
||
| 509 | |||
| 510 | /** |
||
| 511 | * @param mixed $categories |
||
| 512 | */ |
||
| 513 | public function setCategories($categories) |
||
| 517 | |||
| 518 | /** |
||
| 519 | * @return mixed |
||
| 520 | */ |
||
| 521 | public function getCurrency() |
||
| 525 | } |
||
| 526 |