| Conditions | 10 |
| Paths | 12 |
| Total Lines | 36 |
| Code Lines | 16 |
| 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 |
||
| 95 | private function findMatchingTicks(int $openTickLength, Cursor $cursor): bool |
||
| 96 | { |
||
| 97 | // Reset the seenBackticks cache if this is a new cursor |
||
| 98 | if ($this->lastCursor === null || $this->lastCursor->get() !== $cursor) { |
||
| 99 | $this->seenBackticks = []; |
||
| 100 | $this->lastCursor = \WeakReference::create($cursor); |
||
| 101 | $this->lastCursorScanned = false; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($openTickLength > self::MAX_BACKTICKS) { |
||
| 105 | return false; |
||
| 106 | } |
||
| 107 | |||
| 108 | // Return if we already know there's no closer |
||
| 109 | if ($this->lastCursorScanned && isset($this->seenBackticks[$openTickLength]) && $this->seenBackticks[$openTickLength] <= $cursor->getPosition()) { |
||
| 110 | return false; |
||
| 111 | } |
||
| 112 | |||
| 113 | while ($ticks = $cursor->match('/`{1,' . self::MAX_BACKTICKS . '}/m')) { |
||
| 114 | $numTicks = \strlen($ticks); |
||
| 115 | |||
| 116 | // Did we find the closer? |
||
| 117 | if ($numTicks === $openTickLength) { |
||
| 118 | return true; |
||
| 119 | } |
||
| 120 | |||
| 121 | // Store position of closer |
||
| 122 | if ($numTicks <= self::MAX_BACKTICKS) { |
||
| 123 | $this->seenBackticks[$numTicks] = $cursor->getPosition() - $numTicks; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | // Got through whole input without finding closer |
||
| 128 | $this->lastCursorScanned = true; |
||
| 129 | |||
| 130 | return false; |
||
| 131 | } |
||
| 133 |