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 |
||
| 16 | class acf_field_radio extends acf_field { |
||
| 17 | |||
| 18 | |||
| 19 | /* |
||
| 20 | * __construct |
||
| 21 | * |
||
| 22 | * This function will setup the field type data |
||
| 23 | * |
||
| 24 | * @type function |
||
| 25 | * @date 5/03/2014 |
||
| 26 | * @since 5.0.0 |
||
| 27 | * |
||
| 28 | * @param n/a |
||
| 29 | * @return n/a |
||
| 30 | */ |
||
|
|
|||
| 31 | |||
| 32 | View Code Duplication | function __construct() { |
|
| 51 | |||
| 52 | |||
| 53 | /* |
||
| 54 | * render_field() |
||
| 55 | * |
||
| 56 | * Create the HTML interface for your field |
||
| 57 | * |
||
| 58 | * @param $field (array) the $field being rendered |
||
| 59 | * |
||
| 60 | * @type action |
||
| 61 | * @since 3.6 |
||
| 62 | * @date 23/01/13 |
||
| 63 | * |
||
| 64 | * @param $field (array) the $field being edited |
||
| 65 | * @return n/a |
||
| 66 | */ |
||
| 67 | |||
| 68 | function render_field( $field ) { |
||
| 170 | |||
| 171 | |||
| 172 | /* |
||
| 173 | * render_field_settings() |
||
| 174 | * |
||
| 175 | * Create extra options for your field. This is rendered when editing a field. |
||
| 176 | * The value of $field['name'] can be used (like bellow) to save extra data to the $field |
||
| 177 | * |
||
| 178 | * @type action |
||
| 179 | * @since 3.6 |
||
| 180 | * @date 23/01/13 |
||
| 181 | * |
||
| 182 | * @param $field - an array holding all the field's data |
||
| 183 | */ |
||
| 184 | |||
| 185 | function render_field_settings( $field ) { |
||
| 244 | |||
| 245 | |||
| 246 | /* |
||
| 247 | * update_field() |
||
| 248 | * |
||
| 249 | * This filter is appied to the $field before it is saved to the database |
||
| 250 | * |
||
| 251 | * @type filter |
||
| 252 | * @since 3.6 |
||
| 253 | * @date 23/01/13 |
||
| 254 | * |
||
| 255 | * @param $field - the field array holding all the field options |
||
| 256 | * @param $post_id - the field group ID (post_type = acf) |
||
| 257 | * |
||
| 258 | * @return $field - the modified field |
||
| 259 | */ |
||
| 260 | |||
| 261 | function update_field( $field ) { |
||
| 270 | |||
| 271 | |||
| 272 | /* |
||
| 273 | * update_value() |
||
| 274 | * |
||
| 275 | * This filter is appied to the $value before it is updated in the db |
||
| 276 | * |
||
| 277 | * @type filter |
||
| 278 | * @since 3.6 |
||
| 279 | * @date 23/01/13 |
||
| 280 | * @todo Fix bug where $field was found via json and has no ID |
||
| 281 | * |
||
| 282 | * @param $value - the value which will be saved in the database |
||
| 283 | * @param $post_id - the $post_id of which the value will be saved |
||
| 284 | * @param $field - the field array holding all the field options |
||
| 285 | * |
||
| 286 | * @return $value - the modified value |
||
| 287 | */ |
||
| 288 | |||
| 289 | function update_value( $value, $post_id, $field ) { |
||
| 328 | |||
| 329 | |||
| 330 | /* |
||
| 331 | * load_value() |
||
| 332 | * |
||
| 333 | * This filter is appied to the $value after it is loaded from the db |
||
| 334 | * |
||
| 335 | * @type filter |
||
| 336 | * @since 5.2.9 |
||
| 337 | * @date 23/01/13 |
||
| 338 | * |
||
| 339 | * @param $value - the value found in the database |
||
| 340 | * @param $post_id - the $post_id from which the value was loaded from |
||
| 341 | * @param $field - the field array holding all the field options |
||
| 342 | * |
||
| 343 | * @return $value - the value to be saved in te database |
||
| 344 | */ |
||
| 345 | |||
| 346 | function load_value( $value, $post_id, $field ) { |
||
| 360 | |||
| 361 | } |
||
| 362 | |||
| 368 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.