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 |
||
8 | abstract class BaseResource |
||
9 | { |
||
10 | const ENDPOINT_APP = 'https://app.futuresimple.com'; |
||
11 | const ENDPOINT_COMMON = 'https://common.futuresimple.com'; |
||
12 | const ENDPOINT_CORE = 'https://core.futuresimple.com'; |
||
13 | const ENDPOINT_CRM = 'https://crm.futuresimple.com'; |
||
14 | const ENDPOINT_LEADS = 'https://leads.futuresimple.com'; |
||
15 | const ENDPOINT_SALES = 'https://sales.futuresimple.com'; |
||
16 | const ENDPOINT_TAGS = 'https://tags.futuresimple.com'; |
||
17 | |||
18 | const PREFIX = 'api/v1'; |
||
19 | |||
20 | /** @var array */ |
||
21 | protected $data = null; |
||
22 | |||
23 | /** |
||
24 | * @param string $resourceClassName Fully classified class name |
||
|
|||
25 | * |
||
26 | * @return string |
||
27 | */ |
||
28 | protected function getClassNameOnly($resourceClassName = null) |
||
36 | |||
37 | /** |
||
38 | * @param string $resourceClassName Fully classified class name |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | public function getResourceName($resourceClassName = null) |
||
48 | |||
49 | /** |
||
50 | * @param string $resourceClassName Fully classified class name |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | protected function getChildResourceName($resourceClassName = null) |
||
61 | |||
62 | /** |
||
63 | * @param array $data |
||
64 | */ |
||
65 | protected function hydrate(array $data) |
||
83 | |||
84 | /** |
||
85 | * @param array $fieldNames |
||
86 | * |
||
87 | * @throws ResourceException when dehydration has been stopped |
||
88 | * @return array |
||
89 | */ |
||
90 | protected function dehydrate(array $fieldNames = []) |
||
123 | |||
124 | /** |
||
125 | * @param string $name |
||
126 | * |
||
127 | * @return bool |
||
128 | */ |
||
129 | View Code Duplication | public function __isset($name) |
|
145 | |||
146 | /** |
||
147 | * @param string $name |
||
148 | * |
||
149 | * @return mixed |
||
150 | */ |
||
151 | View Code Duplication | public function __get($name) |
|
167 | |||
168 | /** |
||
169 | * @param string $name |
||
170 | * @param mixed $value |
||
171 | */ |
||
172 | public function __set($name, $value) |
||
183 | |||
184 | /** |
||
185 | * @param array $data |
||
186 | * |
||
187 | * @codeCoverageIgnore |
||
188 | */ |
||
189 | protected function postHydrate(array $data) |
||
193 | |||
194 | /** |
||
195 | * @param array $fieldNames |
||
196 | * |
||
197 | * @return array|bool False: stop dehydration, array: new field names |
||
198 | * |
||
199 | * @codeCoverageIgnore |
||
200 | */ |
||
201 | protected function preDehydrate(array $fieldNames) |
||
205 | |||
206 | /** |
||
207 | * @param array $data |
||
208 | * |
||
209 | * @codeCoverageIgnore |
||
210 | */ |
||
211 | protected function postDehydrate(array &$data) |
||
215 | } |
||
216 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.