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_google_map 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() { |
||
| 59 | |||
| 60 | |||
| 61 | /* |
||
| 62 | * render_field() |
||
| 63 | * |
||
| 64 | * Create the HTML interface for your field |
||
| 65 | * |
||
| 66 | * @param $field - an array holding all the field's data |
||
| 67 | * |
||
| 68 | * @type action |
||
| 69 | * @since 3.6 |
||
| 70 | * @date 23/01/13 |
||
| 71 | */ |
||
| 72 | |||
| 73 | function render_field( $field ) { |
||
| 149 | |||
| 150 | |||
| 151 | /* |
||
| 152 | * render_field_settings() |
||
| 153 | * |
||
| 154 | * Create extra options for your field. This is rendered when editing a field. |
||
| 155 | * The value of $field['name'] can be used (like bellow) to save extra data to the $field |
||
| 156 | * |
||
| 157 | * @type action |
||
| 158 | * @since 3.6 |
||
| 159 | * @date 23/01/13 |
||
| 160 | * |
||
| 161 | * @param $field - an array holding all the field's data |
||
| 162 | */ |
||
| 163 | |||
| 164 | function render_field_settings( $field ) { |
||
| 212 | |||
| 213 | |||
| 214 | /* |
||
| 215 | * validate_value |
||
| 216 | * |
||
| 217 | * description |
||
| 218 | * |
||
| 219 | * @type function |
||
| 220 | * @date 11/02/2014 |
||
| 221 | * @since 5.0.0 |
||
| 222 | * |
||
| 223 | * @param $post_id (int) |
||
| 224 | * @return $post_id (int) |
||
| 225 | */ |
||
| 226 | |||
| 227 | View Code Duplication | function validate_value( $valid, $value, $field, $input ){ |
|
| 248 | |||
| 249 | |||
| 250 | /* |
||
| 251 | * update_value() |
||
| 252 | * |
||
| 253 | * This filter is appied to the $value before it is updated in the db |
||
| 254 | * |
||
| 255 | * @type filter |
||
| 256 | * @since 3.6 |
||
| 257 | * @date 23/01/13 |
||
| 258 | * |
||
| 259 | * @param $value - the value which will be saved in the database |
||
| 260 | * @param $post_id - the $post_id of which the value will be saved |
||
| 261 | * @param $field - the field array holding all the field options |
||
| 262 | * |
||
| 263 | * @return $value - the modified value |
||
| 264 | */ |
||
| 265 | |||
| 266 | View Code Duplication | function update_value( $value, $post_id, $field ) { |
|
| 278 | } |
||
| 279 | |||
| 285 |
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.