| Conditions | 12 |
| Paths | 11 |
| Total Lines | 40 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 96 | protected function expandCSSEscape($string) |
||
| 97 | { |
||
| 98 | // flexibly parse it |
||
| 99 | $ret = ''; |
||
| 100 | for ($i = 0, $c = strlen($string); $i < $c; $i++) { |
||
| 101 | if ($string[$i] === '\\') { |
||
| 102 | $i++; |
||
| 103 | if ($i >= $c) { |
||
| 104 | $ret .= '\\'; |
||
| 105 | break; |
||
| 106 | } |
||
| 107 | if (ctype_xdigit($string[$i])) { |
||
| 108 | $code = $string[$i]; |
||
| 109 | for ($a = 1, $i++; $i < $c && $a < 6; $i++, $a++) { |
||
| 110 | if (!ctype_xdigit($string[$i])) { |
||
| 111 | break; |
||
| 112 | } |
||
| 113 | $code .= $string[$i]; |
||
| 114 | } |
||
| 115 | // We have to be extremely careful when adding |
||
| 116 | // new characters, to make sure we're not breaking |
||
| 117 | // the encoding. |
||
| 118 | $char = HTMLPurifier_Encoder::unichr(hexdec($code)); |
||
| 119 | if (HTMLPurifier_Encoder::cleanUTF8($char) === '') { |
||
| 120 | continue; |
||
| 121 | } |
||
| 122 | $ret .= $char; |
||
| 123 | if ($i < $c && trim($string[$i]) !== '') { |
||
| 124 | $i--; |
||
| 125 | } |
||
| 126 | continue; |
||
| 127 | } |
||
| 128 | if ($string[$i] === "\n") { |
||
| 129 | continue; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | $ret .= $string[$i]; |
||
| 133 | } |
||
| 134 | return $ret; |
||
| 135 | } |
||
| 136 | } |
||
| 139 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.