Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
14 | class ScheduledPromotedTweet extends Analytics |
||
15 | { |
||
16 | const RESOURCE_COLLECTION = 'accounts/{account_id}/scheduled_promoted_tweets'; |
||
17 | const RESOURCE = 'accounts/{account_id}/scheduled_promoted_tweets/{id}'; |
||
18 | const RESOURCE_STATS = 'stats/accounts/{account_id}/scheduled_promoted_tweets/{id}'; |
||
19 | |||
20 | const ENTITY = 'PROMOTED_TWEET'; |
||
21 | |||
22 | /** Read Only */ |
||
23 | protected $id; |
||
24 | protected $approval_status; |
||
25 | protected $created_at; |
||
26 | protected $updated_at; |
||
27 | protected $deleted; |
||
28 | |||
29 | protected $properties = [ |
||
30 | ScheduledPromotedTweetFields::TWEET_ID, |
||
31 | ScheduledPromotedTweetFields::ENTITY_STATUS, |
||
32 | ]; |
||
33 | |||
34 | /** Writable */ |
||
35 | protected $tweet_id; |
||
36 | protected $paused; |
||
37 | |||
38 | /** |
||
39 | * @param $metricGroups |
||
40 | * @param array $params |
||
41 | * @param bool $async |
||
42 | * @return mixed |
||
43 | * @throws BadRequest |
||
44 | * @throws \Hborras\TwitterAdsSDK\TwitterAdsException |
||
45 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\Forbidden |
||
46 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotAuthorized |
||
47 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotFound |
||
48 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\RateLimit |
||
49 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError |
||
50 | * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServiceUnavailable |
||
51 | */ |
||
52 | public function stats($metricGroups, $params = [], $async = false) |
||
57 | |||
58 | /** |
||
59 | * Saves or updates the current object instance depending on the |
||
60 | * presence of `object->getId()`. |
||
61 | */ |
||
62 | View Code Duplication | public function save() |
|
83 | |||
84 | /** |
||
85 | * @return mixed |
||
86 | */ |
||
87 | public function getId() |
||
91 | |||
92 | /** |
||
93 | * @return mixed |
||
94 | */ |
||
95 | public function getApprovalStatus() |
||
99 | |||
100 | /** |
||
101 | * @return mixed |
||
102 | */ |
||
103 | public function getCreatedAt() |
||
107 | |||
108 | /** |
||
109 | * @return mixed |
||
110 | */ |
||
111 | public function getUpdatedAt() |
||
115 | |||
116 | /** |
||
117 | * @return mixed |
||
118 | */ |
||
119 | public function getDeleted() |
||
123 | |||
124 | /** |
||
125 | * @return mixed |
||
126 | */ |
||
127 | public function getTweetId() |
||
131 | |||
132 | /** |
||
133 | * @return mixed |
||
134 | */ |
||
135 | public function getPaused() |
||
139 | |||
140 | /** |
||
141 | * @param array $properties |
||
142 | */ |
||
143 | public function setProperties($properties) |
||
147 | |||
148 | /** |
||
149 | * @param mixed $tweet_id |
||
150 | */ |
||
151 | public function setTweetId($tweet_id) |
||
155 | |||
156 | /** |
||
157 | * @param mixed $paused |
||
158 | */ |
||
159 | public function setPaused($paused) |
||
163 | } |
||
164 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.