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 |
||
16 | class LineItem extends Analytics |
||
17 | { |
||
18 | const RESOURCE_COLLECTION = 'accounts/{account_id}/line_items'; |
||
19 | const RESOURCE = 'accounts/{account_id}/line_items/{id}'; |
||
20 | |||
21 | const ENTITY = "LINE_ITEM"; |
||
22 | |||
23 | /** Read Only */ |
||
24 | protected $id; |
||
25 | protected $created_at; |
||
26 | protected $updated_at; |
||
27 | protected $deleted; |
||
28 | |||
29 | protected $properties = [ |
||
30 | LineItemFields::CAMPAIGN_ID, |
||
31 | LineItemFields::BID_AMOUNT_LOCAL_MICRO, |
||
32 | LineItemFields::NAME, |
||
33 | LineItemFields::BID_TYPE, |
||
34 | LineItemFields::AUTOMATICALLY_SELECT_BID, |
||
35 | LineItemFields::PRODUCT_TYPE, |
||
36 | LineItemFields::PLACEMENTS, |
||
37 | LineItemFields::OBJECTIVE, |
||
38 | LineItemFields::PAUSED, |
||
39 | LineItemFields::INCLUDE_SENTIMENT, |
||
40 | LineItemFields::TOTAL_BUDGET_AMOUNT_LOCAL_MICRO, |
||
41 | LineItemFields::START_TIME, |
||
42 | LineItemFields::END_TIME, |
||
43 | LineItemFields::PRIMARY_WEB_EVENT_TAG, |
||
44 | LineItemFields::OPTIMIZATION, |
||
45 | LineItemFields::BID_UNIT, |
||
46 | LineItemFields::CHARGE_BY, |
||
47 | LineItemFields::ADVERTISER_DOMAIN, |
||
48 | LineItemFields::ADVERTISER_USER_ID |
||
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 $paused; |
||
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 | |||
73 | public function getPromotedTweets($params = []) |
||
79 | |||
80 | /** |
||
81 | * Returns a collection of targeting criteria available to the |
||
82 | * current line item. |
||
83 | * |
||
84 | * @param string $id |
||
85 | * @param array $params |
||
86 | * |
||
87 | * @return Cursor | Resource |
||
88 | * |
||
89 | * @throws TwitterAdsException |
||
90 | */ |
||
91 | public function getTargetingCriteria($id = '', $params = []) |
||
104 | |||
105 | /** |
||
106 | * @return mixed |
||
107 | */ |
||
108 | public function getId() |
||
112 | |||
113 | /** |
||
114 | * @return mixed |
||
115 | */ |
||
116 | public function getCreatedAt() |
||
120 | |||
121 | /** |
||
122 | * @return mixed |
||
123 | */ |
||
124 | public function getUpdatedAt() |
||
128 | |||
129 | /** |
||
130 | * @return mixed |
||
131 | */ |
||
132 | public function getDeleted() |
||
136 | |||
137 | /** |
||
138 | * @return array |
||
139 | */ |
||
140 | public function getProperties() |
||
144 | |||
145 | /** |
||
146 | * @param array $properties |
||
147 | */ |
||
148 | public function setProperties($properties) |
||
152 | |||
153 | /** |
||
154 | * @return mixed |
||
155 | */ |
||
156 | public function getCampaignId() |
||
160 | |||
161 | /** |
||
162 | * @param mixed $campaign_id |
||
163 | */ |
||
164 | public function setCampaignId($campaign_id) |
||
168 | |||
169 | /** |
||
170 | * @return mixed |
||
171 | */ |
||
172 | public function getBidAmountLocalMicro() |
||
176 | |||
177 | /** |
||
178 | * @param mixed $bid_amount_local_micro |
||
179 | */ |
||
180 | public function setBidAmountLocalMicro($bid_amount_local_micro) |
||
184 | |||
185 | /** |
||
186 | * @return mixed |
||
187 | */ |
||
188 | public function getName() |
||
192 | |||
193 | /** |
||
194 | * @param mixed $name |
||
195 | */ |
||
196 | public function setName($name) |
||
200 | |||
201 | /** |
||
202 | * @return mixed |
||
203 | */ |
||
204 | public function getBidType() |
||
208 | |||
209 | /** |
||
210 | * @param mixed $bid_type |
||
211 | */ |
||
212 | public function setBidType($bid_type) |
||
216 | |||
217 | /** |
||
218 | * @return mixed |
||
219 | */ |
||
220 | public function getAutomaticallySelectdBid() |
||
224 | |||
225 | /** |
||
226 | * @param mixed $automatically_select_bid |
||
227 | */ |
||
228 | public function setAutomaticallySelectBid($automatically_select_bid) |
||
232 | |||
233 | /** |
||
234 | * @return mixed |
||
235 | */ |
||
236 | public function getProductType() |
||
240 | |||
241 | /** |
||
242 | * @param mixed $product_type |
||
243 | */ |
||
244 | public function setProductType($product_type) |
||
248 | |||
249 | /** |
||
250 | * @return mixed |
||
251 | */ |
||
252 | public function getPlacements() |
||
256 | |||
257 | /** |
||
258 | * @param mixed $placements |
||
259 | */ |
||
260 | public function setPlacements($placements) |
||
264 | |||
265 | /** |
||
266 | * @return mixed |
||
267 | */ |
||
268 | public function getObjective() |
||
272 | |||
273 | /** |
||
274 | * @param mixed $objective |
||
275 | */ |
||
276 | public function setObjective($objective) |
||
280 | |||
281 | /** |
||
282 | * @return mixed |
||
283 | */ |
||
284 | public function getPaused() |
||
288 | |||
289 | /** |
||
290 | * @param mixed $paused |
||
291 | */ |
||
292 | public function setPaused($paused) |
||
296 | |||
297 | /** |
||
298 | * @return mixed |
||
299 | */ |
||
300 | public function getIncludeSentiment() |
||
304 | |||
305 | /** |
||
306 | * @param mixed $include_sentiment |
||
307 | */ |
||
308 | public function setIncludeSentiment($include_sentiment) |
||
312 | |||
313 | /** |
||
314 | * @return mixed |
||
315 | */ |
||
316 | public function getTotalBudgetAmountLocalMicro() |
||
320 | |||
321 | /** |
||
322 | * @param mixed $total_budget_amount_local_micro |
||
323 | */ |
||
324 | public function setTotalBudgetAmountLocalMicro($total_budget_amount_local_micro) |
||
328 | |||
329 | /** |
||
330 | * @return mixed |
||
331 | */ |
||
332 | public function getStartTime() |
||
336 | |||
337 | /** |
||
338 | * @param mixed $start_time |
||
339 | */ |
||
340 | public function setStartTime($start_time) |
||
344 | |||
345 | /** |
||
346 | * @return mixed |
||
347 | */ |
||
348 | public function getEndTime() |
||
352 | |||
353 | /** |
||
354 | * @param mixed $end_time |
||
355 | */ |
||
356 | public function setEndTime($end_time) |
||
360 | |||
361 | /** |
||
362 | * @return mixed |
||
363 | */ |
||
364 | public function getPrimaryWebEventTag() |
||
368 | |||
369 | /** |
||
370 | * @param mixed $primary_web_event_tag |
||
371 | */ |
||
372 | public function setPrimaryWebEventTag($primary_web_event_tag) |
||
376 | |||
377 | /** |
||
378 | * @return mixed |
||
379 | */ |
||
380 | public function getOptimization() |
||
384 | |||
385 | /** |
||
386 | * @param mixed $optimization |
||
387 | */ |
||
388 | public function setOptimization($optimization) |
||
392 | |||
393 | /** |
||
394 | * @return mixed |
||
395 | */ |
||
396 | public function getBidUnit() |
||
400 | |||
401 | /** |
||
402 | * @param mixed $bid_unit |
||
403 | */ |
||
404 | public function setBidUnit($bid_unit) |
||
408 | |||
409 | /** |
||
410 | * @return mixed |
||
411 | */ |
||
412 | public function getChargeBy() |
||
416 | |||
417 | /** |
||
418 | * @param mixed $charge_by |
||
419 | */ |
||
420 | public function setChargeBy($charge_by) |
||
424 | |||
425 | /** |
||
426 | * @return mixed |
||
427 | */ |
||
428 | public function getAdvertiserDomain() |
||
432 | |||
433 | /** |
||
434 | * @param mixed $advertiser_domain |
||
435 | */ |
||
436 | public function setAdvertiserDomain($advertiser_domain) |
||
440 | |||
441 | /** |
||
442 | * @return mixed |
||
443 | */ |
||
444 | public function getTrackingTags() |
||
448 | |||
449 | /** |
||
450 | * @param mixed $tracking_tags |
||
451 | */ |
||
452 | public function setTrackingTags($tracking_tags) |
||
456 | |||
457 | /** |
||
458 | * @return mixed |
||
459 | */ |
||
460 | public function getAdvertiserUserId() |
||
464 | |||
465 | /** |
||
466 | * @param mixed $advertiser_user_id |
||
467 | */ |
||
468 | public function setAdvertiserUserId($advertiser_user_id) |
||
472 | } |
||
473 |