| Conditions | 13 |
| Paths | 17 |
| Total Lines | 33 |
| Lines | 6 |
| Ratio | 18.18 % |
| 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 | function __construct($s, $mode = self::TOKEN_HTML) { |
||
|
|
|||
| 52 | $m = array(); |
||
| 53 | $pos = 0; |
||
| 54 | $this->nodes = array(); |
||
| 55 | $rFlag = PREG_OFFSET_CAPTURE + PREG_SET_ORDER; |
||
| 56 | if (strlen(trim($s)) == 0) return; |
||
| 57 | if ($mode == self::TOKEN_CONTROL) { |
||
| 58 | if (preg_match('/^"(.*)"$/', trim($s), $m)) { |
||
| 59 | $this->nodes[] = new Text($m[1]); |
||
| 60 | } else |
||
| 61 | $this->nodes[] = new Text\Complex(trim($s)); |
||
| 62 | return; |
||
| 63 | } |
||
| 64 | preg_match_all(self::REGEX_HTML, $s, $m, $rFlag); |
||
| 65 | foreach ($m as $match) { |
||
| 66 | if ($mode & self::FIND_BARDOLLAR && isset($match[2])) { |
||
| 67 | View Code Duplication | if ($match[2][1] != $pos) |
|
| 68 | $this->nodes[] = new Text\Plain( |
||
| 69 | substr($s, $pos, $match[2][1] - $pos), $mode); |
||
| 70 | $this->nodes[] = new Text\Complex(substr($match[2][0], 1, -1)); |
||
| 71 | $pos = $match[2][1] + strlen($match[2][0]); |
||
| 72 | } elseif ($mode & self::FIND_DOLLARVAR) { |
||
| 73 | if ($match[1][1] > 0 && $s[$match[1][1] - 1] == '\\') continue; |
||
| 74 | View Code Duplication | if ($match[1][1] != $pos) |
|
| 75 | $this->nodes[] = new Text\Plain( |
||
| 76 | substr($s, $pos, $match[1][1] - $pos), $mode); |
||
| 77 | $this->nodes[] = new Text\SimpleVar($match[1][0]); |
||
| 78 | $pos = $match[1][1] + strlen($match[1][0]); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | if ($pos != strlen($s)) |
||
| 82 | $this->nodes[] = new Text\Plain(substr($s, $pos), $mode); |
||
| 83 | } |
||
| 84 | |||
| 134 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.