Conditions | 11 |
Paths | 512 |
Total Lines | 43 |
Code Lines | 26 |
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 |
||
51 | public function php($text) |
||
52 | { |
||
53 | $text = trim($text); |
||
54 | $addedtag_open = 0; |
||
55 | if (!strpos($text, '<?php') && (substr($text, 0, 5) !== '<?php')) { |
||
56 | $text = '<?php ' . $text; |
||
57 | $addedtag_open = 1; |
||
58 | } |
||
59 | $addedtag_close = 0; |
||
60 | if (!strpos($text, '?>')) { |
||
61 | $text .= '?>'; |
||
62 | $addedtag_close = 1; |
||
63 | } |
||
64 | $oldlevel = error_reporting(0); |
||
65 | |||
66 | //There is a bug in the highlight function(php < 5.3) that it doesn't render |
||
67 | //backslashes properly like in \s. So here we replace any backslashes |
||
68 | $text = str_replace("\\", 'XxxX', $text); |
||
69 | |||
70 | $buffer = highlight_string($text, true); // Require PHP 4.20+ |
||
71 | |||
72 | //Placing backspaces back again |
||
73 | $buffer = str_replace('XxxX', "\\", $buffer); |
||
74 | |||
75 | error_reporting($oldlevel); |
||
76 | $pos_open = $pos_close = 0; |
||
77 | if ($addedtag_open) { |
||
78 | $pos_open = strpos($buffer, '<?php '); |
||
79 | } |
||
80 | if ($addedtag_close) { |
||
81 | $pos_close = strrpos($buffer, '?>'); |
||
82 | } |
||
83 | |||
84 | $str_open = $addedtag_open ? substr($buffer, 0, $pos_open) : ''; |
||
85 | $str_close = $pos_close ? substr($buffer, $pos_close + 5) : ''; |
||
86 | |||
87 | $length_open = $addedtag_open ? $pos_open + 14 : 0; |
||
88 | $length_text = $pos_close ? $pos_close - $length_open : 0; |
||
89 | $str_internal = $length_text ? substr($buffer, $length_open, $length_text) : substr($buffer, $length_open); |
||
90 | |||
91 | $buffer = $str_open . $str_internal . $str_close; |
||
92 | |||
93 | return $buffer; |
||
94 | } |
||
96 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.