Conditions | 22 |
Paths | 220 |
Total Lines | 77 |
Lines | 0 |
Ratio | 0 % |
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 |
||
134 | private static function is_mobile( $kind = 'any', $return_matched_agent = false, $ua_info ) { |
||
135 | $kinds = array( |
||
136 | 'smart' => false, |
||
137 | 'dumb' => false, |
||
138 | 'any' => false, |
||
139 | ); |
||
140 | $first_run = true; |
||
141 | $matched_agent = ''; |
||
142 | |||
143 | // If an invalid kind is passed in, reset it to default. |
||
144 | if ( ! isset( $kinds[ $kind ] ) ) { |
||
145 | $kind = 'any'; |
||
146 | } |
||
147 | |||
148 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) || strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ), 'ipad' ) ) { |
||
149 | return false; |
||
150 | } |
||
151 | |||
152 | // Remove Samsung Galaxy tablets (SCH-I800) from being mobile devices. |
||
153 | if ( strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ), 'sch-i800' ) ) { |
||
154 | return false; |
||
155 | } |
||
156 | |||
157 | if ( $ua_info->is_android_tablet() && false === $ua_info->is_kindle_touch() ) { |
||
158 | return false; |
||
159 | } |
||
160 | |||
161 | if ( $ua_info->is_blackberry_tablet() ) { |
||
162 | return false; |
||
163 | } |
||
164 | |||
165 | if ( $first_run ) { |
||
166 | $first_run = false; |
||
167 | |||
168 | // checks for iPhoneTier devices & RichCSS devices. |
||
169 | if ( $ua_info->isTierIphone() || $ua_info->isTierRichCSS() ) { |
||
170 | $kinds['smart'] = true; |
||
171 | $matched_agent = $ua_info->matched_agent; |
||
172 | } |
||
173 | |||
174 | if ( ! $kinds['smart'] ) { |
||
175 | // if smart, we are not dumb so no need to check. |
||
176 | $dumb_agents = $ua_info->dumb_agents; |
||
177 | $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
178 | |||
179 | foreach ( $dumb_agents as $dumb_agent ) { |
||
180 | if ( false !== strpos( $agent, $dumb_agent ) ) { |
||
181 | $kinds['dumb'] = true; |
||
182 | $matched_agent = $dumb_agent; |
||
183 | |||
184 | break; |
||
185 | } |
||
186 | } |
||
187 | |||
188 | if ( ! $kinds['dumb'] ) { |
||
189 | if ( isset( $_SERVER['HTTP_X_WAP_PROFILE'] ) ) { |
||
190 | $kinds['dumb'] = true; |
||
191 | $matched_agent = 'http_x_wap_profile'; |
||
192 | } elseif ( isset( $_SERVER['HTTP_ACCEPT'] ) && ( preg_match( '/wap\.|\.wap/i', $_SERVER['HTTP_ACCEPT'] ) || false !== strpos( strtolower( $_SERVER['HTTP_ACCEPT'] ), 'application/vnd.wap.xhtml+xml' ) ) ) { |
||
193 | $kinds['dumb'] = true; |
||
194 | $matched_agent = 'vnd.wap.xhtml+xml'; |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | |||
199 | if ( $kinds['dumb'] || $kinds['smart'] ) { |
||
200 | $kinds['any'] = true; |
||
201 | } |
||
202 | } |
||
203 | |||
204 | $value = $kinds[ $kind ]; |
||
205 | |||
206 | if ( $return_matched_agent ) { |
||
207 | $value = $matched_agent; |
||
208 | } |
||
209 | return $value; |
||
210 | } |
||
211 | } |
||
212 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.