Conditions | 12 |
Paths | 21 |
Total Lines | 41 |
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 |
||
94 | private static function manuallyParseLinkDestination(Cursor $cursor): ?string |
||
95 | { |
||
96 | $oldPosition = $cursor->getPosition(); |
||
97 | $oldState = $cursor->saveState(); |
||
98 | |||
99 | $openParens = 0; |
||
100 | while (($c = $cursor->getCharacter()) !== null) { |
||
101 | if ($c === '\\' && $cursor->peek() !== null && RegexHelper::isEscapable($cursor->peek())) { |
||
102 | $cursor->advanceBy(2); |
||
103 | } elseif ($c === '(') { |
||
104 | $cursor->advance(); |
||
105 | $openParens++; |
||
106 | } elseif ($c === ')') { |
||
107 | if ($openParens < 1) { |
||
108 | break; |
||
109 | } |
||
110 | |||
111 | $cursor->advance(); |
||
112 | $openParens--; |
||
113 | } elseif (\preg_match(RegexHelper::REGEX_WHITESPACE_CHAR, $c)) { |
||
114 | break; |
||
115 | } else { |
||
116 | $cursor->advance(); |
||
117 | } |
||
118 | } |
||
119 | |||
120 | if ($openParens !== 0) { |
||
121 | return null; |
||
122 | } |
||
123 | |||
124 | if ($cursor->getPosition() === $oldPosition && $c !== ')') { |
||
125 | return null; |
||
126 | } |
||
127 | |||
128 | $newPos = $cursor->getPosition(); |
||
129 | $cursor->restoreState($oldState); |
||
130 | |||
131 | $cursor->advanceBy($newPos - $cursor->getPosition()); |
||
132 | |||
133 | return $cursor->getPreviousText(); |
||
134 | } |
||
135 | } |
||
136 |