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_checkbox 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() { |
|
| 49 | |||
| 50 | |||
| 51 | /* |
||
| 52 | * render_field() |
||
| 53 | * |
||
| 54 | * Create the HTML interface for your field |
||
| 55 | * |
||
| 56 | * @param $field (array) the $field being rendered |
||
| 57 | * |
||
| 58 | * @type action |
||
| 59 | * @since 3.6 |
||
| 60 | * @date 23/01/13 |
||
| 61 | * |
||
| 62 | * @param $field (array) the $field being edited |
||
| 63 | * @return n/a |
||
| 64 | */ |
||
| 65 | |||
| 66 | function render_field( $field ) { |
||
| 184 | |||
| 185 | |||
| 186 | /* |
||
| 187 | * render_field_settings() |
||
| 188 | * |
||
| 189 | * Create extra options for your field. This is rendered when editing a field. |
||
| 190 | * The value of $field['name'] can be used (like bellow) to save extra data to the $field |
||
| 191 | * |
||
| 192 | * @type action |
||
| 193 | * @since 3.6 |
||
| 194 | * @date 23/01/13 |
||
| 195 | * |
||
| 196 | * @param $field - an array holding all the field's data |
||
| 197 | */ |
||
| 198 | |||
| 199 | function render_field_settings( $field ) { |
||
| 253 | |||
| 254 | |||
| 255 | /* |
||
| 256 | * update_field() |
||
| 257 | * |
||
| 258 | * This filter is appied to the $field before it is saved to the database |
||
| 259 | * |
||
| 260 | * @type filter |
||
| 261 | * @since 3.6 |
||
| 262 | * @date 23/01/13 |
||
| 263 | * |
||
| 264 | * @param $field - the field array holding all the field options |
||
| 265 | * @param $post_id - the field group ID (post_type = acf) |
||
| 266 | * |
||
| 267 | * @return $field - the modified field |
||
| 268 | */ |
||
| 269 | |||
| 270 | View Code Duplication | function update_field( $field ) { |
|
| 280 | |||
| 281 | |||
| 282 | /* |
||
| 283 | * update_value() |
||
| 284 | * |
||
| 285 | * This filter is appied to the $value before it is updated in the db |
||
| 286 | * |
||
| 287 | * @type filter |
||
| 288 | * @since 3.6 |
||
| 289 | * @date 23/01/13 |
||
| 290 | * |
||
| 291 | * @param $value - the value which will be saved in the database |
||
| 292 | * @param $post_id - the $post_id of which the value will be saved |
||
| 293 | * @param $field - the field array holding all the field options |
||
| 294 | * |
||
| 295 | * @return $value - the modified value |
||
| 296 | */ |
||
| 297 | |||
| 298 | View Code Duplication | function update_value( $value, $post_id, $field ) { |
|
| 320 | |||
| 321 | } |
||
| 322 | |||
| 328 |
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.