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_number 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 | function __construct() { |
||
| 53 | |||
| 54 | |||
| 55 | /* |
||
| 56 | * render_field() |
||
| 57 | * |
||
| 58 | * Create the HTML interface for your field |
||
| 59 | * |
||
| 60 | * @param $field - an array holding all the field's data |
||
| 61 | * |
||
| 62 | * @type action |
||
| 63 | * @since 3.6 |
||
| 64 | * @date 23/01/13 |
||
| 65 | */ |
||
| 66 | |||
| 67 | function render_field( $field ) { |
||
| 131 | |||
| 132 | |||
| 133 | /* |
||
| 134 | * render_field_settings() |
||
| 135 | * |
||
| 136 | * Create extra options for your field. This is rendered when editing a field. |
||
| 137 | * The value of $field['name'] can be used (like bellow) to save extra data to the $field |
||
| 138 | * |
||
| 139 | * @type action |
||
| 140 | * @since 3.6 |
||
| 141 | * @date 23/01/13 |
||
| 142 | * |
||
| 143 | * @param $field - an array holding all the field's data |
||
| 144 | */ |
||
| 145 | |||
| 146 | function render_field_settings( $field ) { |
||
| 211 | |||
| 212 | |||
| 213 | /* |
||
| 214 | * validate_value |
||
| 215 | * |
||
| 216 | * description |
||
| 217 | * |
||
| 218 | * @type function |
||
| 219 | * @date 11/02/2014 |
||
| 220 | * @since 5.0.0 |
||
| 221 | * |
||
| 222 | * @param $post_id (int) |
||
| 223 | * @return $post_id (int) |
||
| 224 | */ |
||
| 225 | |||
| 226 | function validate_value( $valid, $value, $field, $input ){ |
||
| 277 | |||
| 278 | |||
| 279 | /* |
||
| 280 | * update_value() |
||
| 281 | * |
||
| 282 | * This filter is appied to the $value before it is updated in the db |
||
| 283 | * |
||
| 284 | * @type filter |
||
| 285 | * @since 3.6 |
||
| 286 | * @date 23/01/13 |
||
| 287 | * |
||
| 288 | * @param $value - the value which will be saved in the database |
||
| 289 | * @param $field - the field array holding all the field options |
||
| 290 | * @param $post_id - the $post_id of which the value will be saved |
||
| 291 | * |
||
| 292 | * @return $value - the modified value |
||
| 293 | */ |
||
| 294 | |||
| 295 | function update_value( $value, $post_id, $field ) { |
||
| 316 | |||
| 317 | |||
| 318 | } |
||
| 319 | |||
| 325 |
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.