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 |
||
12 | final class TailoredAudiencePermission extends Resource |
||
13 | { |
||
14 | const RESOURCE_COLLECTION = 'accounts/{account_id}/tailored_audiences/{tailored_audience_id/permissions}'; |
||
15 | const RESOURCE = 'accounts/{account_id}/tailored_audiences/{tailored_audience_id/permissions}/{id}'; |
||
16 | const RESOURCE_TAILORED_AUDIENCE_ID_REPLACE = '{tailored_audience_id}'; |
||
17 | |||
18 | |||
19 | /** Writable */ |
||
20 | protected $tailored_audience_id; |
||
21 | protected $granted_account_id; |
||
22 | protected $permission_level; |
||
23 | |||
24 | protected $properties = [ |
||
25 | 'tailored_audience_id', |
||
26 | 'granted_account_id', |
||
27 | 'permission_level' |
||
28 | ]; |
||
29 | |||
30 | /** Read Only */ |
||
31 | protected $deleted; |
||
32 | protected $id; |
||
33 | protected $updated_at; |
||
34 | protected $created_at; |
||
35 | |||
36 | /** |
||
37 | * Returns a Cursor instance for the given tailored audience permission resource. |
||
38 | * |
||
39 | * @param array $tailoredAudienceId |
||
40 | * @param array $params |
||
41 | * @return Cursor |
||
42 | */ |
||
43 | View Code Duplication | public function all($tailoredAudienceId, $params = []) |
|
52 | |||
53 | /** |
||
54 | * Saves or updates the current tailored audience permission. |
||
55 | * |
||
56 | * @return $this |
||
57 | */ |
||
58 | public function save() |
||
73 | |||
74 | /** |
||
75 | * Saves or updates the current tailored audience permission. |
||
76 | * |
||
77 | * @return $this |
||
78 | */ |
||
79 | public function delete() |
||
88 | |||
89 | /** |
||
90 | * @return mixed |
||
91 | */ |
||
92 | public function getTailoredAudienceId() |
||
96 | |||
97 | /** |
||
98 | * @param mixed $tailored_audience_id |
||
99 | */ |
||
100 | public function setTailoredAudienceId($tailored_audience_id) |
||
104 | |||
105 | /** |
||
106 | * @return mixed |
||
107 | */ |
||
108 | public function getGrantedAccountId() |
||
112 | |||
113 | /** |
||
114 | * @param mixed $granted_account_id |
||
115 | */ |
||
116 | public function setGrantedAccountId($granted_account_id) |
||
120 | |||
121 | /** |
||
122 | * @return mixed |
||
123 | */ |
||
124 | public function getPermissionLevel() |
||
128 | |||
129 | /** |
||
130 | * @param mixed $permission_level |
||
131 | */ |
||
132 | public function setPermissionLevel($permission_level) |
||
136 | |||
137 | /** |
||
138 | * @return mixed |
||
139 | */ |
||
140 | public function getDeleted() |
||
144 | |||
145 | /** |
||
146 | * @return mixed |
||
147 | */ |
||
148 | public function getId() |
||
152 | |||
153 | /** |
||
154 | * @return mixed |
||
155 | */ |
||
156 | public function getUpdatedAt() |
||
160 | |||
161 | /** |
||
162 | * @return mixed |
||
163 | */ |
||
164 | public function getCreatedAt() |
||
168 | } |
||
169 |
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.