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 |
||
18 | class LineItem extends Analytics |
||
19 | { |
||
20 | const RESOURCE_COLLECTION = 'accounts/{account_id}/line_items'; |
||
21 | const RESOURCE = 'accounts/{account_id}/line_items/{id}'; |
||
22 | |||
23 | const ENTITY = 'LINE_ITEM'; |
||
24 | |||
25 | /** Read Only */ |
||
26 | protected $id; |
||
27 | protected $created_at; |
||
28 | protected $updated_at; |
||
29 | protected $deleted; |
||
30 | protected $target_cpa_local_micro; |
||
31 | protected $currency; |
||
32 | |||
33 | protected $properties = [ |
||
34 | LineItemFields::CAMPAIGN_ID, |
||
35 | LineItemFields::BID_AMOUNT_LOCAL_MICRO, |
||
36 | LineItemFields::NAME, |
||
37 | LineItemFields::BID_TYPE, |
||
38 | LineItemFields::AUTOMATICALLY_SELECT_BID, |
||
39 | LineItemFields::PRODUCT_TYPE, |
||
40 | LineItemFields::PLACEMENTS, |
||
41 | LineItemFields::OBJECTIVE, |
||
42 | LineItemFields::ENTITY_STATUS, |
||
43 | LineItemFields::INCLUDE_SENTIMENT, |
||
44 | LineItemFields::TOTAL_BUDGET_AMOUNT_LOCAL_MICRO, |
||
45 | LineItemFields::START_TIME, |
||
46 | LineItemFields::END_TIME, |
||
47 | LineItemFields::PRIMARY_WEB_EVENT_TAG, |
||
48 | LineItemFields::OPTIMIZATION, |
||
49 | LineItemFields::BID_UNIT, |
||
50 | LineItemFields::CHARGE_BY, |
||
51 | LineItemFields::ADVERTISER_DOMAIN, |
||
52 | LineItemFields::ADVERTISER_USER_ID, |
||
53 | LineItemFields::CATEGORIES |
||
54 | ]; |
||
55 | |||
56 | /** Writable */ |
||
57 | protected $campaign_id; |
||
58 | protected $bid_amount_local_micro; |
||
59 | protected $name; |
||
60 | protected $bid_type; |
||
61 | protected $automatically_select_bid; |
||
62 | protected $product_type; |
||
63 | protected $placements; |
||
64 | protected $objective; |
||
65 | protected $entity_status; |
||
66 | protected $include_sentiment; |
||
67 | protected $total_budget_amount_local_micro; |
||
68 | protected $start_time; |
||
69 | protected $end_time; |
||
70 | protected $primary_web_event_tag; |
||
71 | protected $optimization; |
||
72 | protected $bid_unit; |
||
73 | protected $charge_by; |
||
74 | protected $advertiser_domain; |
||
75 | protected $tracking_tags; |
||
76 | protected $advertiser_user_id; |
||
77 | protected $categories; |
||
78 | |||
79 | /** |
||
80 | * @param array $params |
||
81 | * @return Cursor|\Hborras\TwitterAdsSDK\TwitterAds\Resource |
||
82 | * @throws BadRequest |
||
83 | * @throws TwitterAdsException |
||
84 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\Forbidden |
||
85 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotAuthorized |
||
86 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotFound |
||
87 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\RateLimit |
||
88 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError |
||
89 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServiceUnavailable |
||
90 | */ |
||
91 | public function getPromotedTweets($params = []) |
||
97 | |||
98 | /** |
||
99 | * @param $metricGroups |
||
100 | * @param array $params |
||
101 | * @param bool $async |
||
102 | * @return Job| mixed |
||
103 | * @throws BadRequest |
||
104 | * @throws TwitterAdsException |
||
105 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\Forbidden |
||
106 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotAuthorized |
||
107 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotFound |
||
108 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\RateLimit |
||
109 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError |
||
110 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServiceUnavailable |
||
111 | */ |
||
112 | public function stats($metricGroups, $params = [], $async = false) |
||
117 | |||
118 | /** |
||
119 | * Returns a collection of targeting criteria available to the |
||
120 | * current line item. |
||
121 | * |
||
122 | * @param string $id |
||
123 | * @param array $params |
||
124 | * |
||
125 | * @return Cursor | Resource |
||
126 | * |
||
127 | * @throws TwitterAdsException |
||
128 | */ |
||
129 | public function getTargetingCriteria($id = '', $params = []) |
||
142 | |||
143 | /** |
||
144 | * @return mixed |
||
145 | */ |
||
146 | public function getId() |
||
150 | |||
151 | /** |
||
152 | * @return mixed |
||
153 | */ |
||
154 | public function getCreatedAt() |
||
158 | |||
159 | /** |
||
160 | * @return mixed |
||
161 | */ |
||
162 | public function getUpdatedAt() |
||
166 | |||
167 | /** |
||
168 | * @return mixed |
||
169 | */ |
||
170 | public function getDeleted() |
||
174 | |||
175 | /** |
||
176 | * @param array $properties |
||
177 | */ |
||
178 | public function setProperties($properties) |
||
182 | |||
183 | /** |
||
184 | * @return mixed |
||
185 | */ |
||
186 | public function getCampaignId() |
||
190 | |||
191 | /** |
||
192 | * @param mixed $campaign_id |
||
193 | */ |
||
194 | public function setCampaignId($campaign_id) |
||
198 | |||
199 | /** |
||
200 | * @return mixed |
||
201 | */ |
||
202 | public function getBidAmountLocalMicro() |
||
206 | |||
207 | /** |
||
208 | * @param mixed $bid_amount_local_micro |
||
209 | */ |
||
210 | public function setBidAmountLocalMicro($bid_amount_local_micro) |
||
214 | |||
215 | /** |
||
216 | * @return mixed |
||
217 | */ |
||
218 | public function getName() |
||
222 | |||
223 | /** |
||
224 | * @param mixed $name |
||
225 | */ |
||
226 | public function setName($name) |
||
230 | |||
231 | /** |
||
232 | * @return mixed |
||
233 | */ |
||
234 | public function getBidType() |
||
238 | |||
239 | /** |
||
240 | * @param mixed $bid_type |
||
241 | */ |
||
242 | public function setBidType($bid_type) |
||
246 | |||
247 | /** |
||
248 | * @return mixed |
||
249 | */ |
||
250 | public function getAutomaticallySelectdBid() |
||
254 | |||
255 | /** |
||
256 | * @param mixed $automatically_select_bid |
||
257 | */ |
||
258 | public function setAutomaticallySelectBid($automatically_select_bid) |
||
262 | |||
263 | /** |
||
264 | * @return mixed |
||
265 | */ |
||
266 | public function getProductType() |
||
270 | |||
271 | /** |
||
272 | * @param mixed $product_type |
||
273 | */ |
||
274 | public function setProductType($product_type) |
||
278 | |||
279 | /** |
||
280 | * @return mixed |
||
281 | */ |
||
282 | public function getPlacements() |
||
286 | |||
287 | /** |
||
288 | * @param mixed $placements |
||
289 | */ |
||
290 | public function setPlacements($placements) |
||
294 | |||
295 | /** |
||
296 | * @return mixed |
||
297 | */ |
||
298 | public function getObjective() |
||
302 | |||
303 | /** |
||
304 | * @param mixed $objective |
||
305 | */ |
||
306 | public function setObjective($objective) |
||
310 | |||
311 | /** |
||
312 | * @return mixed |
||
313 | */ |
||
314 | public function getEntityStatus() |
||
318 | |||
319 | /** |
||
320 | * @param mixed $entity_status |
||
321 | */ |
||
322 | public function setEntityStatus($entity_status) |
||
326 | |||
327 | /** |
||
328 | * @return mixed |
||
329 | */ |
||
330 | public function getIncludeSentiment() |
||
334 | |||
335 | /** |
||
336 | * @param mixed $include_sentiment |
||
337 | */ |
||
338 | public function setIncludeSentiment($include_sentiment) |
||
342 | |||
343 | /** |
||
344 | * @return mixed |
||
345 | */ |
||
346 | public function getTotalBudgetAmountLocalMicro() |
||
350 | |||
351 | /** |
||
352 | * @param mixed $total_budget_amount_local_micro |
||
353 | */ |
||
354 | public function setTotalBudgetAmountLocalMicro($total_budget_amount_local_micro) |
||
358 | |||
359 | /** |
||
360 | * @return mixed |
||
361 | */ |
||
362 | public function getStartTime() |
||
366 | |||
367 | /** |
||
368 | * @param mixed $start_time |
||
369 | */ |
||
370 | public function setStartTime($start_time) |
||
374 | |||
375 | /** |
||
376 | * @return mixed |
||
377 | */ |
||
378 | public function getEndTime() |
||
382 | |||
383 | /** |
||
384 | * @param mixed $end_time |
||
385 | */ |
||
386 | public function setEndTime($end_time) |
||
390 | |||
391 | /** |
||
392 | * @return mixed |
||
393 | */ |
||
394 | public function getPrimaryWebEventTag() |
||
398 | |||
399 | /** |
||
400 | * @param mixed $primary_web_event_tag |
||
401 | */ |
||
402 | public function setPrimaryWebEventTag($primary_web_event_tag) |
||
406 | |||
407 | /** |
||
408 | * @return mixed |
||
409 | */ |
||
410 | public function getOptimization() |
||
414 | |||
415 | /** |
||
416 | * @param mixed $optimization |
||
417 | */ |
||
418 | public function setOptimization($optimization) |
||
422 | |||
423 | /** |
||
424 | * @return mixed |
||
425 | */ |
||
426 | public function getBidUnit() |
||
430 | |||
431 | /** |
||
432 | * @param mixed $bid_unit |
||
433 | */ |
||
434 | public function setBidUnit($bid_unit) |
||
438 | |||
439 | /** |
||
440 | * @return mixed |
||
441 | */ |
||
442 | public function getChargeBy() |
||
446 | |||
447 | /** |
||
448 | * @param mixed $charge_by |
||
449 | */ |
||
450 | public function setChargeBy($charge_by) |
||
454 | |||
455 | /** |
||
456 | * @return mixed |
||
457 | */ |
||
458 | public function getAdvertiserDomain() |
||
462 | |||
463 | /** |
||
464 | * @param mixed $advertiser_domain |
||
465 | */ |
||
466 | public function setAdvertiserDomain($advertiser_domain) |
||
470 | |||
471 | /** |
||
472 | * @return mixed |
||
473 | */ |
||
474 | public function getTrackingTags() |
||
478 | |||
479 | /** |
||
480 | * @param mixed $tracking_tags |
||
481 | */ |
||
482 | public function setTrackingTags($tracking_tags) |
||
486 | |||
487 | /** |
||
488 | * @return mixed |
||
489 | */ |
||
490 | public function getAdvertiserUserId() |
||
494 | |||
495 | /** |
||
496 | * @param mixed $advertiser_user_id |
||
497 | */ |
||
498 | public function setAdvertiserUserId($advertiser_user_id) |
||
502 | |||
503 | /** |
||
504 | * @return mixed |
||
505 | */ |
||
506 | public function getTargetCpaLocalMicro() |
||
510 | |||
511 | /** |
||
512 | * @return mixed |
||
513 | */ |
||
514 | public function getAutomaticallySelectBid() |
||
518 | |||
519 | /** |
||
520 | * @return mixed |
||
521 | */ |
||
522 | public function getCategories() |
||
526 | |||
527 | /** |
||
528 | * @param mixed $categories |
||
529 | */ |
||
530 | public function setCategories($categories) |
||
534 | |||
535 | /** |
||
536 | * @return mixed |
||
537 | */ |
||
538 | public function getCurrency() |
||
542 | } |
||
543 |