Conditions | 39 |
Paths | > 20000 |
Total Lines | 147 |
Code Lines | 99 |
Lines | 6 |
Ratio | 4.08 % |
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 if ( !defined( 'ABSPATH' ) ) exit; |
||
290 | protected function _analiseCode($code) |
||
291 | { |
||
292 | // name of the tag, opening, closure, autoclosure |
||
293 | $tag = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)'; |
||
294 | if (!preg_match('/'.$tag.'/isU', $code, $match)) return null; |
||
295 | $close = ($match[1]=='/' ? true : false); |
||
296 | $autoclose = preg_match('/\/>$/isU', $code); |
||
297 | $name = strtolower($match[2]); |
||
298 | |||
299 | // required parameters (depends on the tag name) |
||
300 | $param = array(); |
||
301 | $param['style'] = ''; |
||
302 | if ($name=='img') { |
||
303 | $param['alt'] = ''; |
||
304 | $param['src'] = ''; |
||
305 | } |
||
306 | if ($name=='a') { |
||
307 | $param['href'] = ''; |
||
308 | } |
||
309 | |||
310 | // read the parameters : nom=valeur |
||
311 | $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
||
312 | preg_match_all('/'.$prop.'/is', $code, $match); |
||
313 | View Code Duplication | for($k=0; $k<count($match[0]); $k++) |
|
314 | $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
||
315 | |||
316 | // read the parameters : nom="valeur" |
||
317 | $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
||
318 | preg_match_all('/'.$prop.'/is', $code, $match); |
||
319 | View Code Duplication | for($k=0; $k<count($match[0]); $k++) |
|
320 | $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
||
321 | |||
322 | // read the parameters : nom='valeur' |
||
323 | $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
||
324 | preg_match_all('/'.$prop.'/is', $code, $match); |
||
325 | View Code Duplication | for($k=0; $k<count($match[0]); $k++) |
|
326 | $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
||
327 | |||
328 | // compliance of each parameter |
||
329 | $color = "#000000"; |
||
330 | $border = null; |
||
331 | foreach ($param as $key => $val) { |
||
332 | $key = strtolower($key); |
||
333 | switch($key) |
||
334 | { |
||
335 | case 'width': |
||
336 | unset($param[$key]); |
||
337 | $param['style'] .= 'width: '.$val.'px; '; |
||
338 | break; |
||
339 | |||
340 | case 'align': |
||
341 | if ($name==='img') { |
||
342 | unset($param[$key]); |
||
343 | $param['style'] .= 'float: '.$val.'; '; |
||
344 | } elseif ($name!=='table') { |
||
345 | unset($param[$key]); |
||
346 | $param['style'] .= 'text-align: '.$val.'; '; |
||
347 | } |
||
348 | break; |
||
349 | |||
350 | case 'valign': |
||
351 | unset($param[$key]); |
||
352 | $param['style'] .= 'vertical-align: '.$val.'; '; |
||
353 | break; |
||
354 | |||
355 | case 'height': |
||
356 | unset($param[$key]); |
||
357 | $param['style'] .= 'height: '.$val.'px; '; |
||
358 | break; |
||
359 | |||
360 | case 'bgcolor': |
||
361 | unset($param[$key]); |
||
362 | $param['style'] .= 'background: '.$val.'; '; |
||
363 | break; |
||
364 | |||
365 | case 'bordercolor': |
||
366 | unset($param[$key]); |
||
367 | $color = $val; |
||
368 | break; |
||
369 | |||
370 | case 'border': |
||
371 | unset($param[$key]); |
||
372 | if (preg_match('/^[0-9]+$/isU', $val)) $val = $val.'px'; |
||
373 | $border = $val; |
||
374 | break; |
||
375 | |||
376 | case 'cellpadding': |
||
377 | case 'cellspacing': |
||
378 | if (preg_match('/^([0-9]+)$/isU', $val)) $param[$key] = $val.'px'; |
||
379 | break; |
||
380 | |||
381 | case 'colspan': |
||
382 | case 'rowspan': |
||
383 | $val = preg_replace('/[^0-9]/isU', '', $val); |
||
384 | if (!$val) $val = 1; |
||
385 | $param[$key] = $val; |
||
386 | break; |
||
387 | } |
||
388 | } |
||
389 | |||
390 | // compliance of the border |
||
391 | if ($border!==null) { |
||
392 | if ($border) $border = 'border: solid '.$border.' '.$color; |
||
393 | else $border = 'border: none'; |
||
394 | |||
395 | $param['style'] .= $border.'; '; |
||
396 | $param['border'] = $border; |
||
397 | } |
||
398 | |||
399 | // reading styles: decomposition and standardization |
||
400 | $styles = explode(';', $param['style']); |
||
401 | $param['style'] = array(); |
||
402 | foreach ($styles as $style) { |
||
403 | $tmp = explode(':', $style); |
||
404 | if (count($tmp)>1) { |
||
405 | $cod = $tmp[0]; |
||
406 | unset($tmp[0]); |
||
407 | $tmp = implode(':', $tmp); |
||
408 | $param['style'][trim(strtolower($cod))] = preg_replace('/[\s]+/isU', ' ', trim($tmp)); |
||
409 | } |
||
410 | } |
||
411 | |||
412 | // determining the level of table opening, with an added level |
||
413 | if (in_array($name, array('ul', 'ol', 'table')) && !$close) { |
||
414 | $this->_num++; |
||
415 | $this->_level[count($this->_level)] = $this->_num; |
||
416 | } |
||
417 | |||
418 | // get the level of the table containing the element |
||
419 | if (!isset($param['num'])) { |
||
420 | $param['num'] = $this->_level[count($this->_level)-1]; |
||
421 | } |
||
422 | |||
423 | // for closures table: remove a level |
||
424 | if (in_array($name, array('ul', 'ol', 'table')) && $close) { |
||
425 | unset($this->_level[count($this->_level)-1]); |
||
426 | } |
||
427 | |||
428 | // prepare the parameters |
||
429 | if (isset($param['value'])) $param['value'] = $this->_prepareTxt($param['value']); |
||
430 | if (isset($param['alt'])) $param['alt'] = $this->_prepareTxt($param['alt']); |
||
431 | if (isset($param['title'])) $param['title'] = $this->_prepareTxt($param['title']); |
||
432 | if (isset($param['class'])) $param['class'] = $this->_prepareTxt($param['class']); |
||
433 | |||
434 | // return the new action to do |
||
435 | return array('name' => $name, 'close' => $close ? 1 : 0, 'autoclose' => $autoclose, 'param' => $param); |
||
436 | } |
||
437 | |||
520 | } |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..