| Conditions | 15 |
| Paths | 22 |
| Total Lines | 38 |
| Code Lines | 24 |
| 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 |
||
| 94 | private static function manuallyParseLinkDestination(Cursor $cursor): ?string |
||
| 95 | { |
||
| 96 | $remainder = $cursor->getRemainder(); |
||
| 97 | $openParens = 0; |
||
| 98 | $len = \strlen($remainder); |
||
| 99 | for ($i = 0; $i < $len; $i++) { |
||
| 100 | $c = $remainder[$i]; |
||
| 101 | if ($c === '\\' && $i + 1 < $len && RegexHelper::isEscapable($remainder[$i + 1])) { |
||
| 102 | $i++; |
||
| 103 | } elseif ($c === '(') { |
||
| 104 | $openParens++; |
||
| 105 | // Limit to 32 nested parens for pathological cases |
||
| 106 | if ($openParens > 32) { |
||
| 107 | return null; |
||
| 108 | } |
||
| 109 | } elseif ($c === ')') { |
||
| 110 | if ($openParens < 1) { |
||
| 111 | break; |
||
| 112 | } |
||
| 113 | |||
| 114 | $openParens--; |
||
| 115 | } elseif (\ord($c) <= 32 && RegexHelper::isWhitespace($c)) { |
||
| 116 | break; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | if ($openParens !== 0) { |
||
|
|
|||
| 121 | return null; |
||
| 122 | } |
||
| 123 | |||
| 124 | if ($i === 0 && (! isset($c) || $c !== ')')) { |
||
| 125 | return null; |
||
| 126 | } |
||
| 127 | |||
| 128 | $destination = \substr($remainder, 0, $i); |
||
| 129 | $cursor->advanceBy(\mb_strlen($destination, 'UTF-8')); |
||
| 130 | |||
| 131 | return $destination; |
||
| 132 | } |
||
| 166 |