| Conditions | 11 |
| Paths | 396 |
| Total Lines | 77 |
| 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 |
||
| 33 | public function debugSequence(\Iterator $sequence): void |
||
| 34 | { |
||
| 35 | $colors = [ |
||
| 36 | "\033[01;0m", |
||
| 37 | "\033[01;31m", |
||
| 38 | "\033[01;32m", |
||
| 39 | "\033[01;34m", |
||
| 40 | "\033[01;35m", |
||
| 41 | "\033[01;36m", |
||
| 42 | ]; |
||
| 43 | |||
| 44 | $reflect = new \ReflectionClass(Context::class); |
||
| 45 | $constants = array_flip($reflect->getConstants()); |
||
| 46 | $legend = ''; |
||
| 47 | foreach ($constants as $index => $constant) { |
||
| 48 | $legend .= $colors[$index] ?? "\033[01;0m"; |
||
| 49 | $legend .= substr($constant, 8); |
||
| 50 | $legend .= "\033[0m"; |
||
| 51 | $legend .= ' '; |
||
| 52 | } |
||
| 53 | |||
| 54 | $captures = []; |
||
| 55 | $symbols = []; |
||
| 56 | $contexts = []; |
||
| 57 | $nesting = []; |
||
| 58 | |||
| 59 | $spacing = ''; |
||
| 60 | |||
| 61 | try { |
||
| 62 | foreach ($sequence as $symbol => $capture) { |
||
| 63 | $captures[] = $capture->captured === null ? null : str_replace(PHP_EOL, '', $capture->captured); |
||
| 64 | $symbols[] = $symbol; |
||
| 65 | $contexts[] = $sequencer->position->context->context; |
||
|
|
|||
| 66 | $nesting[] = count($sequencer->position->stack); |
||
| 67 | } |
||
| 68 | } catch (\RuntimeException $exception) { |
||
| 69 | $this->writeLogLine($exception->getMessage(), 31); |
||
| 70 | } |
||
| 71 | |||
| 72 | |||
| 73 | $this->writeLogLine(PHP_EOL); |
||
| 74 | $this->writeLogLine($legend); |
||
| 75 | $this->writeLogLine(str_repeat('—', strlen(str_replace(PHP_EOL, '', $sequencer->source->source)))); |
||
| 76 | |||
| 77 | $symbolLine = ''; |
||
| 78 | foreach ($symbols as $index => $symbol) { |
||
| 79 | $char = $symbol === Splitter::BYTE_BACKSLASH ? '\\' : chr($symbol); |
||
| 80 | $capturedLength = strlen((string)$captures[$index]) + 1; |
||
| 81 | $symbolLine .= $colors[$contexts[$index]] ?? "\033[01;0m"; |
||
| 82 | $symbolLine .= str_repeat(' ', max($capturedLength - 1, 0)) . $char . $spacing; |
||
| 83 | #echo str_repeat((string)$contexts[$index], $capturedLength > 0 ? $capturedLength : 1); |
||
| 84 | $symbolLine .= "\033[0m"; |
||
| 85 | } |
||
| 86 | |||
| 87 | $this->writeLogLine($symbolLine, 0); |
||
| 88 | |||
| 89 | $captureLine = ''; |
||
| 90 | foreach ($captures as $index => $capture) { |
||
| 91 | $char = $symbol === Splitter::BYTE_BACKSLASH ? '\\' : chr($symbol); |
||
| 92 | $captureLine .= $colors[$contexts[$index]] ?? "\033[01;0m"; |
||
| 93 | $captureLine .= $capture; |
||
| 94 | //$captureLine .= str_pad(addslashes(chr($symbols[$index])), 1, ' ') . ' '; |
||
| 95 | $captureLine .= str_repeat(' ', strlen($char)) . $spacing; |
||
| 96 | $captureLine .= "\033[0m"; |
||
| 97 | } |
||
| 98 | |||
| 99 | $this->writeLogLine($captureLine); |
||
| 100 | |||
| 101 | $nestingLine = ''; |
||
| 102 | foreach ($nesting as $index => $depth) { |
||
| 103 | $capturedLength = strlen(str_replace(PHP_EOL, '', (string)$captures[$index])) + 1; |
||
| 104 | $nestingLine .= str_repeat((string)$depth, ($capturedLength > 0 ? $capturedLength : 0)) . $spacing; |
||
| 105 | } |
||
| 106 | |||
| 107 | $this->writeLogLine($nestingLine); |
||
| 108 | $this->writeLogLine(str_repeat('—', strlen(str_replace(PHP_EOL, '', $sequencer->source->source)))); |
||
| 109 | } |
||
| 110 | } |
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.