Conditions | 12 |
Paths | 1536 |
Total Lines | 68 |
Code Lines | 40 |
Lines | 12 |
Ratio | 17.65 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
57 | public function __construct( array $config = [] ) { |
||
58 | $config = array_merge( [ |
||
59 | // Default config values |
||
60 | 'precision' => 'day', |
||
61 | ], $config ); |
||
62 | |||
63 | // Properties |
||
64 | if ( isset( $config['inputFormat'] ) ) { |
||
65 | $this->inputFormat = $config['inputFormat']; |
||
66 | } |
||
67 | if ( isset( $config['placeholderDateFormat'] ) ) { |
||
68 | $this->placeholderDateFormat = $config['placeholderDateFormat']; |
||
69 | } |
||
70 | $this->precision = $config['precision']; |
||
71 | if ( isset( $config['mustBeAfter'] ) ) { |
||
72 | $this->mustBeAfter = $config['mustBeAfter']; |
||
73 | } |
||
74 | if ( isset( $config['mustBeBefore'] ) ) { |
||
75 | $this->mustBeBefore = $config['mustBeBefore']; |
||
76 | } |
||
77 | |||
78 | // Properties stored for the infused JS widget |
||
79 | if ( isset( $config['displayFormat'] ) ) { |
||
80 | $this->displayFormat = $config['displayFormat']; |
||
81 | } |
||
82 | if ( isset( $config['placeholderLabel'] ) ) { |
||
83 | $this->placeholderLabel = $config['placeholderLabel']; |
||
84 | } |
||
85 | if ( isset( $config['overlay'] ) ) { |
||
86 | $this->overlay = $config['overlay']; |
||
87 | } |
||
88 | |||
89 | // Set up placeholder text visible if the browser doesn't override it (logic taken from JS) |
||
90 | if ( $this->placeholderDateFormat !== null ) { |
||
91 | $placeholder = $this->placeholderDateFormat; |
||
92 | } elseif ( $this->inputFormat !== null ) { |
||
93 | // We have no way to display a translated placeholder for custom formats |
||
94 | $placeholder = ''; |
||
95 | } else { |
||
96 | $placeholder = wfMessage( "mw-widgets-dateinput-placeholder-$this->precision" )->text(); |
||
97 | } |
||
98 | |||
99 | $config = array_merge( [ |
||
100 | // Processed config values |
||
101 | 'placeholder' => $placeholder, |
||
102 | ], $config ); |
||
103 | |||
104 | // Parent constructor |
||
105 | parent::__construct( $config ); |
||
106 | |||
107 | // Calculate min/max attributes (which are skipped by TextInputWidget) and add to <input> |
||
108 | // min/max attributes are inclusive, but mustBeAfter/Before are exclusive |
||
109 | View Code Duplication | if ( $this->mustBeAfter !== null ) { |
|
110 | $min = new DateTime( $this->mustBeAfter ); |
||
111 | $min = $min->modify( '+1 day' ); |
||
112 | $min = $min->format( 'Y-m-d' ); |
||
113 | $this->input->setAttributes( [ 'min' => $min ] ); |
||
114 | } |
||
115 | View Code Duplication | if ( $this->mustBeBefore !== null ) { |
|
116 | $max = new DateTime( $this->mustBeBefore ); |
||
117 | $max = $max->modify( '-1 day' ); |
||
118 | $max = $max->format( 'Y-m-d' ); |
||
119 | $this->input->setAttributes( [ 'max' => $max ] ); |
||
120 | } |
||
121 | |||
122 | // Initialization |
||
123 | $this->addClasses( [ 'mw-widget-dateInputWidget' ] ); |
||
124 | } |
||
125 | |||
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.