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 |
||
18 | class DateInputWidget extends \OOUI\TextInputWidget { |
||
19 | |||
20 | protected $inputFormat = null; |
||
21 | protected $displayFormat = null; |
||
22 | protected $placeholderLabel = null; |
||
23 | protected $placeholderDateFormat = null; |
||
24 | protected $precision = null; |
||
25 | protected $mustBeAfter = null; |
||
26 | protected $mustBeBefore = null; |
||
27 | protected $overlay = null; |
||
28 | |||
29 | /** |
||
30 | * @param array $config Configuration options |
||
31 | * @param string $config['inputFormat'] Date format string to use for the textual input field. |
||
|
|||
32 | * Displayed while the widget is active, and the user can type in a date in this format. |
||
33 | * Should be short and easy to type. (default: 'YYYY-MM-DD' or 'YYYY-MM', depending on |
||
34 | * `precision`) |
||
35 | * @param string $config['displayFormat'] Date format string to use for the clickable label. |
||
36 | * while the widget is inactive. Should be as unambiguous as possible (for example, prefer |
||
37 | * to spell out the month, rather than rely on the order), even if that makes it longer. |
||
38 | * Applicable only if the widget is infused. (default: language-specific) |
||
39 | * @param string $config['placeholderLabel'] Placeholder text shown when the widget is not |
||
40 | * selected. Applicable only if the widget is infused. (default: taken from message |
||
41 | * `mw-widgets-dateinput-no-date`) |
||
42 | * @param string $config['placeholderDateFormat'] User-visible date format string displayed |
||
43 | * in the textual input field when it's empty. Should be the same as `inputFormat`, but |
||
44 | * translated to the user's language. (default: 'YYYY-MM-DD' or 'YYYY-MM', depending on |
||
45 | * `precision`) |
||
46 | * @param string $config['precision'] Date precision to use, 'day' or 'month' (default: 'day') |
||
47 | * @param string $config['mustBeAfter'] Validates the date to be after this. |
||
48 | * In the 'YYYY-MM-DD' or 'YYYY-MM' format, depending on `precision`. |
||
49 | * @param string $config['mustBeBefore'] Validates the date to be before this. |
||
50 | * In the 'YYYY-MM-DD' or 'YYYY-MM' format, depending on `precision`. |
||
51 | * @param string $config['overlay'] The jQuery selector for the overlay layer on which to render |
||
52 | * the calendar. This configuration is useful in cases where the expanded calendar is larger |
||
53 | * than its container. The specified overlay layer is usually on top of the container and has |
||
54 | * a larger area. Applicable only if the widget is infused. By default, the calendar uses |
||
55 | * relative positioning. |
||
56 | */ |
||
57 | public function __construct( array $config = [] ) { |
||
125 | |||
126 | protected function getJavaScriptClassName() { |
||
129 | |||
130 | public function getConfig( &$config ) { |
||
157 | |||
158 | public function getInputElement( $config ) { |
||
165 | } |
||
166 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.