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 |
||
| 20 | class BaseInput extends BaseField { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Field ID. |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | private $field_id; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Field's classes |
||
| 31 | * |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | private $classes = []; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Field placeholder. |
||
| 38 | * |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | private $placeholder; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Field name. |
||
| 45 | * |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | private $name; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Field value. |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | private $value; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Construct Field |
||
| 59 | * |
||
| 60 | * @param string $id Fields ID. |
||
|
|
|||
| 61 | * @param array $classes Field and label classes. |
||
| 62 | * @param string $placeholder Fields placeholder. |
||
| 63 | * @param string $name Field name. |
||
| 64 | */ |
||
| 65 | public function __construct( $classes, $placeholder, $label, $value, $description, $merge, $form_id, $hidden ) { |
||
| 75 | |||
| 76 | const TYPE = 'text'; |
||
| 77 | const REQUIRED = false; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Get Field Type |
||
| 81 | * |
||
| 82 | * @return string $field['type'] |
||
| 83 | */ |
||
| 84 | public function get_type() { |
||
| 87 | |||
| 88 | public function get_placeholder() { |
||
| 91 | |||
| 92 | public function field_classes() { |
||
| 95 | |||
| 96 | public function label_classes() { |
||
| 99 | |||
| 100 | public function get_name() { |
||
| 103 | |||
| 104 | public function get_id() { |
||
| 107 | |||
| 108 | public function get_value() { |
||
| 111 | |||
| 112 | public function set_description( $description ) { |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Render the field. |
||
| 120 | * |
||
| 121 | * @since %VERSION% |
||
| 122 | */ |
||
| 123 | public function render() { |
||
| 168 | } |
||
| 169 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.