| Conditions | 11 |
| Paths | 10 |
| Total Lines | 43 |
| Code Lines | 30 |
| 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 |
||
| 70 | private function parseList(Cursor $cursor, bool $inParagraph): ?ListData |
||
| 71 | { |
||
| 72 | $indent = $cursor->getIndent(); |
||
| 73 | |||
| 74 | $tmpCursor = clone $cursor; |
||
| 75 | $tmpCursor->advanceToNextNonSpaceOrTab(); |
||
| 76 | $rest = $tmpCursor->getRemainder(); |
||
| 77 | |||
| 78 | if (\preg_match($this->listMarkerRegex ?? $this->generateListMarkerRegex(), $rest) === 1) { |
||
| 79 | $data = new ListData(); |
||
| 80 | $data->markerOffset = $indent; |
||
| 81 | $data->type = ListBlock::TYPE_BULLET; |
||
| 82 | $data->delimiter = null; |
||
| 83 | $data->bulletChar = $rest[0]; |
||
| 84 | $markerLength = 1; |
||
| 85 | } elseif (($matches = RegexHelper::matchFirst('/^(\d{1,9})([.)])/', $rest)) && (! $inParagraph || $matches[1] === '1')) { |
||
| 86 | $data = new ListData(); |
||
| 87 | $data->markerOffset = $indent; |
||
| 88 | $data->type = ListBlock::TYPE_ORDERED; |
||
| 89 | $data->start = (int) $matches[1]; |
||
| 90 | $data->delimiter = $matches[2] === '.' ? ListBlock::DELIM_PERIOD : ListBlock::DELIM_PAREN; |
||
| 91 | $data->bulletChar = null; |
||
| 92 | $markerLength = \strlen($matches[0]); |
||
| 93 | } else { |
||
| 94 | return null; |
||
| 95 | } |
||
| 96 | |||
| 97 | // Make sure we have spaces after |
||
| 98 | $nextChar = $tmpCursor->peek($markerLength); |
||
| 99 | if (! ($nextChar === null || $nextChar === "\t" || $nextChar === ' ')) { |
||
| 100 | return null; |
||
| 101 | } |
||
| 102 | |||
| 103 | // If it interrupts paragraph, make sure first line isn't blank |
||
| 104 | if ($inParagraph && ! RegexHelper::matchAt(RegexHelper::REGEX_NON_SPACE, $rest, $markerLength)) { |
||
|
|
|||
| 105 | return null; |
||
| 106 | } |
||
| 107 | |||
| 108 | $cursor->advanceToNextNonSpaceOrTab(); // to start of marker |
||
| 109 | $cursor->advanceBy($markerLength, true); // to end of marker |
||
| 110 | $data->padding = self::calculateListMarkerPadding($cursor, $markerLength); |
||
| 111 | |||
| 112 | return $data; |
||
| 113 | } |
||
| 155 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: