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_textarea 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 - an array holding all the field's data |
||
| 59 | * |
||
| 60 | * @type action |
||
| 61 | * @since 3.6 |
||
| 62 | * @date 23/01/13 |
||
| 63 | */ |
||
| 64 | |||
| 65 | function render_field( $field ) { |
||
| 119 | |||
| 120 | /* |
||
| 121 | * render_field_settings() |
||
| 122 | * |
||
| 123 | * Create extra options for your field. This is rendered when editing a field. |
||
| 124 | * The value of $field['name'] can be used (like bellow) to save extra data to the $field |
||
| 125 | * |
||
| 126 | * @param $field - an array holding all the field's data |
||
| 127 | * |
||
| 128 | * @type action |
||
| 129 | * @since 3.6 |
||
| 130 | * @date 23/01/13 |
||
| 131 | */ |
||
| 132 | |||
| 133 | function render_field_settings( $field ) { |
||
| 194 | |||
| 195 | |||
| 196 | /* |
||
| 197 | * format_value() |
||
| 198 | * |
||
| 199 | * This filter is applied to the $value after it is loaded from the db and before it is returned to the template |
||
| 200 | * |
||
| 201 | * @type filter |
||
| 202 | * @since 3.6 |
||
| 203 | * @date 23/01/13 |
||
| 204 | * |
||
| 205 | * @param $value (mixed) the value which was loaded from the database |
||
| 206 | * @param $post_id (mixed) the $post_id from which the value was loaded |
||
| 207 | * @param $field (array) the field array holding all the field options |
||
| 208 | * |
||
| 209 | * @return $value (mixed) the modified value |
||
| 210 | */ |
||
| 211 | |||
| 212 | function format_value( $value, $post_id, $field ) { |
||
| 237 | |||
| 238 | } |
||
| 239 | |||
| 245 |
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.