@@ -19,10 +19,10 @@ |
||
| 19 | 19 | use ContextTrait; |
| 20 | 20 | |
| 21 | 21 | public function __construct( |
| 22 | - public Mixin|string $name, |
|
| 22 | + public Mixin | string $name, |
|
| 23 | 23 | public mixed $value, |
| 24 | 24 | ?Context $context = null |
| 25 | - ) { |
|
| 25 | + ){ |
|
| 26 | 26 | $this->context = $context; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | /** @internal */ |
| 24 | 24 | public array $tokens, |
| 25 | 25 | ?Context $context = null |
| 26 | - ) { |
|
| 26 | + ){ |
|
| 27 | 27 | $this->context = $context; |
| 28 | 28 | } |
| 29 | 29 | |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | public function __construct( |
| 24 | 24 | public array $nodes = [], |
| 25 | 25 | ?Context $context = null |
| 26 | - ) { |
|
| 26 | + ){ |
|
| 27 | 27 | $this->context = $context; |
| 28 | 28 | } |
| 29 | 29 | |
@@ -17,9 +17,9 @@ |
||
| 17 | 17 | use ContextTrait; |
| 18 | 18 | |
| 19 | 19 | public function __construct( |
| 20 | - public string|int|float $content, |
|
| 20 | + public string | int | float $content, |
|
| 21 | 21 | ?Context $context = null |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | $this->context = $context; |
| 24 | 24 | } |
| 25 | 25 | |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | ?int $int = 123, |
| 21 | 21 | ?\StdClass $nullableClass2 = null, |
| 22 | 22 | string ...$variadicVar |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | $var2 = new ATest3(); |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | private readonly ConflictResolver\Names $namesResolver, |
| 26 | 26 | private readonly ConflictResolver\Namespaces $namespacesResolver, |
| 27 | 27 | ?Parser $parser = null |
| 28 | - ) { |
|
| 28 | + ){ |
|
| 29 | 29 | $this->parser = $parser ?? (new ParserFactory())->create(ParserFactory::ONLY_PHP7); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -58,11 +58,11 @@ discard block |
||
| 58 | 58 | $declarator = new DeclareClass(); |
| 59 | 59 | $this->traverse($filename, $declarator); |
| 60 | 60 | |
| 61 | - if (empty($declarator->getClass())) { |
|
| 61 | + if (empty($declarator->getClass())){ |
|
| 62 | 62 | throw new ClassNotDeclaredException($filename); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if ($declarator->getNamespace()) { |
|
| 65 | + if ($declarator->getNamespace()){ |
|
| 66 | 66 | return ClassNode::createWithNamespace($declarator->getClass(), $declarator->getNamespace()); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $tr = new NodeTraverser(); |
| 75 | 75 | |
| 76 | - foreach ($visitors as $visitor) { |
|
| 76 | + foreach ($visitors as $visitor){ |
|
| 77 | 77 | $tr->addVisitor($visitor); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | private function fillStmts(ClassNode $definition, array $imports): void |
| 84 | 84 | { |
| 85 | - foreach ($imports as $import) { |
|
| 85 | + foreach ($imports as $import){ |
|
| 86 | 86 | $definition->addImportUsage($import['name'], $import['alias']); |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | $reflection = new \ReflectionClass(\sprintf('%s\%s', $definition->namespace, $definition->class)); |
| 96 | 96 | |
| 97 | 97 | $constructor = $reflection->getConstructor(); |
| 98 | - if ($constructor !== null) { |
|
| 98 | + if ($constructor !== null){ |
|
| 99 | 99 | $definition->hasConstructor = $constructor->getDeclaringClass()->getName() === $reflection->getName(); |
| 100 | 100 | |
| 101 | - foreach ($reflection->getConstructor()->getParameters() as $parameter) { |
|
| 101 | + foreach ($reflection->getConstructor()->getParameters() as $parameter){ |
|
| 102 | 102 | $definition->addParam($parameter); |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | private function fillConstructorVars(array $vars, ClassNode $definition): void |
| 112 | 112 | { |
| 113 | - foreach ($vars as $k => $var) { |
|
| 114 | - if (isset($definition->constructorParams[$var])) { |
|
| 113 | + foreach ($vars as $k => $var){ |
|
| 114 | + if (isset($definition->constructorParams[$var])){ |
|
| 115 | 115 | unset($vars[$k]); |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | public function __construct( |
| 29 | 29 | ?Lexer $lexer = null, |
| 30 | 30 | private readonly PrettyPrinterAbstract $printer = new Standard() |
| 31 | - ) { |
|
| 31 | + ){ |
|
| 32 | 32 | $this->lexer = $lexer ?? new Lexer\Emulative([ |
| 33 | 33 | 'usedAttributes' => [ |
| 34 | 34 | 'comments', |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function injectDependencies(string $code, ClassNode $node, bool $removeTrait = false): string |
| 53 | 53 | { |
| 54 | - if (empty($node->dependencies)) { |
|
| 55 | - if ($removeTrait) { |
|
| 54 | + if (empty($node->dependencies)){ |
|
| 55 | + if ($removeTrait){ |
|
| 56 | 56 | $tr = new NodeTraverser(); |
| 57 | 57 | $tr->addVisitor(new RemoveUse()); |
| 58 | 58 | $tr->addVisitor(new RemoveTrait()); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $tr = new NodeTraverser(); |
| 67 | 67 | $tr->addVisitor(new AddUse($node)); |
| 68 | 68 | |
| 69 | - if ($removeTrait) { |
|
| 69 | + if ($removeTrait){ |
|
| 70 | 70 | $tr->addVisitor(new RemoveUse()); |
| 71 | 71 | $tr->addVisitor(new RemoveTrait()); |
| 72 | 72 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | ): string { |
| 23 | 23 | $verbosity ??= $this->defaultVerbosity; |
| 24 | 24 | $exceptions = [$exception]; |
| 25 | - while ($exception = $exception->getPrevious()) { |
|
| 25 | + while ($exception = $exception->getPrevious()){ |
|
| 26 | 26 | $exceptions[] = $exception; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $result = []; |
| 32 | 32 | $rootDir = \getcwd(); |
| 33 | 33 | |
| 34 | - foreach ($exceptions as $exception) { |
|
| 34 | + foreach ($exceptions as $exception){ |
|
| 35 | 35 | $file = \str_starts_with($exception->getFile(), $rootDir) |
| 36 | 36 | ? \substr($exception->getFile(), \strlen($rootDir) + 1) |
| 37 | 37 | : $exception->getFile(); |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | $exception->getLine(), |
| 45 | 45 | ); |
| 46 | 46 | |
| 47 | - if ($verbosity->value >= Verbosity::DEBUG->value) { |
|
| 47 | + if ($verbosity->value >= Verbosity::DEBUG->value){ |
|
| 48 | 48 | $row .= $this->renderTrace($exception, new Highlighter(new PlainStyle())); |
| 49 | - } elseif ($verbosity->value >= Verbosity::VERBOSE->value) { |
|
| 49 | + } elseif ($verbosity->value >= Verbosity::VERBOSE->value){ |
|
| 50 | 50 | $row .= $this->renderTrace($exception); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | private function renderTrace(\Throwable $e, ?Highlighter $h = null): string |
| 65 | 65 | { |
| 66 | 66 | $stacktrace = $this->getStacktrace($e); |
| 67 | - if ($stacktrace === []) { |
|
| 67 | + if ($stacktrace === []){ |
|
| 68 | 68 | return ''; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -73,45 +73,45 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | $pad = \strlen((string)\count($stacktrace)); |
| 75 | 75 | |
| 76 | - foreach ($stacktrace as $i => $trace) { |
|
| 77 | - if (isset($trace['type'], $trace['class'])) { |
|
| 76 | + foreach ($stacktrace as $i => $trace){ |
|
| 77 | + if (isset($trace['type'], $trace['class'])){ |
|
| 78 | 78 | $line = \sprintf( |
| 79 | 79 | '%s. %s%s%s()', |
| 80 | - \str_pad((string)((int) $i + 1), $pad, ' ', \STR_PAD_LEFT), |
|
| 80 | + \str_pad((string)((int)$i + 1), $pad, ' ', \STR_PAD_LEFT), |
|
| 81 | 81 | $trace['class'], |
| 82 | 82 | $trace['type'], |
| 83 | 83 | $trace['function'] |
| 84 | 84 | ); |
| 85 | - } else { |
|
| 85 | + }else{ |
|
| 86 | 86 | $line = $trace['function']; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if (isset($trace['file'])) { |
|
| 90 | - $file = (string) $trace['file']; |
|
| 89 | + if (isset($trace['file'])){ |
|
| 90 | + $file = (string)$trace['file']; |
|
| 91 | 91 | \str_starts_with($file, $rootDir) and $file = \substr($file, \strlen($rootDir) + 1); |
| 92 | 92 | |
| 93 | 93 | $line .= \sprintf(' at %s:%s', $file, $trace['line']); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if (\in_array($line, $this->lines, true)) { |
|
| 96 | + if (\in_array($line, $this->lines, true)){ |
|
| 97 | 97 | continue; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $this->lines[] = $line; |
| 101 | 101 | |
| 102 | - $result .= $line . "\n"; |
|
| 102 | + $result .= $line."\n"; |
|
| 103 | 103 | |
| 104 | - if ($h !== null && !empty($trace['file']) && \is_file($trace['file'])) { |
|
| 104 | + if ($h !== null && !empty($trace['file']) && \is_file($trace['file'])){ |
|
| 105 | 105 | $str = @\file_get_contents($trace['file']); |
| 106 | 106 | $result .= $h->highlightLines( |
| 107 | 107 | $str, |
| 108 | 108 | $trace['line'], |
| 109 | 109 | self::SHOW_LINES |
| 110 | - ) . "\n"; |
|
| 110 | + )."\n"; |
|
| 111 | 111 | unset($str); |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - return $result . "\n"; |
|
| 115 | + return $result."\n"; |
|
| 116 | 116 | } |
| 117 | 117 | } |
@@ -22,7 +22,8 @@ discard block |
||
| 22 | 22 | ): string { |
| 23 | 23 | $verbosity ??= $this->defaultVerbosity; |
| 24 | 24 | $exceptions = [$exception]; |
| 25 | - while ($exception = $exception->getPrevious()) { |
|
| 25 | + while ($exception = $exception->getPrevious()) |
|
| 26 | + { |
|
| 26 | 27 | $exceptions[] = $exception; |
| 27 | 28 | } |
| 28 | 29 | |
@@ -31,7 +32,8 @@ discard block |
||
| 31 | 32 | $result = []; |
| 32 | 33 | $rootDir = \getcwd(); |
| 33 | 34 | |
| 34 | - foreach ($exceptions as $exception) { |
|
| 35 | + foreach ($exceptions as $exception) |
|
| 36 | + { |
|
| 35 | 37 | $file = \str_starts_with($exception->getFile(), $rootDir) |
| 36 | 38 | ? \substr($exception->getFile(), \strlen($rootDir) + 1) |
| 37 | 39 | : $exception->getFile(); |
@@ -44,9 +46,12 @@ discard block |
||
| 44 | 46 | $exception->getLine(), |
| 45 | 47 | ); |
| 46 | 48 | |
| 47 | - if ($verbosity->value >= Verbosity::DEBUG->value) { |
|
| 49 | + if ($verbosity->value >= Verbosity::DEBUG->value) |
|
| 50 | + { |
|
| 48 | 51 | $row .= $this->renderTrace($exception, new Highlighter(new PlainStyle())); |
| 49 | - } elseif ($verbosity->value >= Verbosity::VERBOSE->value) { |
|
| 52 | + } |
|
| 53 | + elseif ($verbosity->value >= Verbosity::VERBOSE->value) |
|
| 54 | + { |
|
| 50 | 55 | $row .= $this->renderTrace($exception); |
| 51 | 56 | } |
| 52 | 57 | |
@@ -64,7 +69,8 @@ discard block |
||
| 64 | 69 | private function renderTrace(\Throwable $e, ?Highlighter $h = null): string |
| 65 | 70 | { |
| 66 | 71 | $stacktrace = $this->getStacktrace($e); |
| 67 | - if ($stacktrace === []) { |
|
| 72 | + if ($stacktrace === []) |
|
| 73 | + { |
|
| 68 | 74 | return ''; |
| 69 | 75 | } |
| 70 | 76 | |
@@ -73,8 +79,10 @@ discard block |
||
| 73 | 79 | |
| 74 | 80 | $pad = \strlen((string)\count($stacktrace)); |
| 75 | 81 | |
| 76 | - foreach ($stacktrace as $i => $trace) { |
|
| 77 | - if (isset($trace['type'], $trace['class'])) { |
|
| 82 | + foreach ($stacktrace as $i => $trace) |
|
| 83 | + { |
|
| 84 | + if (isset($trace['type'], $trace['class'])) |
|
| 85 | + { |
|
| 78 | 86 | $line = \sprintf( |
| 79 | 87 | '%s. %s%s%s()', |
| 80 | 88 | \str_pad((string)((int) $i + 1), $pad, ' ', \STR_PAD_LEFT), |
@@ -82,18 +90,22 @@ discard block |
||
| 82 | 90 | $trace['type'], |
| 83 | 91 | $trace['function'] |
| 84 | 92 | ); |
| 85 | - } else { |
|
| 93 | + } |
|
| 94 | + else |
|
| 95 | + { |
|
| 86 | 96 | $line = $trace['function']; |
| 87 | 97 | } |
| 88 | 98 | |
| 89 | - if (isset($trace['file'])) { |
|
| 99 | + if (isset($trace['file'])) |
|
| 100 | + { |
|
| 90 | 101 | $file = (string) $trace['file']; |
| 91 | 102 | \str_starts_with($file, $rootDir) and $file = \substr($file, \strlen($rootDir) + 1); |
| 92 | 103 | |
| 93 | 104 | $line .= \sprintf(' at %s:%s', $file, $trace['line']); |
| 94 | 105 | } |
| 95 | 106 | |
| 96 | - if (\in_array($line, $this->lines, true)) { |
|
| 107 | + if (\in_array($line, $this->lines, true)) |
|
| 108 | + { |
|
| 97 | 109 | continue; |
| 98 | 110 | } |
| 99 | 111 | |
@@ -101,7 +113,8 @@ discard block |
||
| 101 | 113 | |
| 102 | 114 | $result .= $line . "\n"; |
| 103 | 115 | |
| 104 | - if ($h !== null && !empty($trace['file']) && \is_file($trace['file'])) { |
|
| 116 | + if ($h !== null && !empty($trace['file']) && \is_file($trace['file'])) |
|
| 117 | + { |
|
| 105 | 118 | $str = @\file_get_contents($trace['file']); |
| 106 | 119 | $result .= $h->highlightLines( |
| 107 | 120 | $str, |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $exceptions = [$exception]; |
| 69 | 69 | $currentE = $exception; |
| 70 | 70 | |
| 71 | - while ($exception = $exception->getPrevious()) { |
|
| 71 | + while ($exception = $exception->getPrevious()){ |
|
| 72 | 72 | $exceptions[] = $exception; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | $result = []; |
| 78 | 78 | $rootDir = \getcwd(); |
| 79 | 79 | |
| 80 | - foreach ($exceptions as $exception) { |
|
| 80 | + foreach ($exceptions as $exception){ |
|
| 81 | 81 | $prefix = $currentE === $exception ? '' : 'Previous: '; |
| 82 | 82 | $row = $this->renderHeader( |
| 83 | 83 | \sprintf("%s[%s]\n%s", $prefix, $exception::class, $exception->getMessage()), |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | $exception->getLine() |
| 95 | 95 | ); |
| 96 | 96 | |
| 97 | - if ($verbosity->value >= Verbosity::DEBUG->value) { |
|
| 97 | + if ($verbosity->value >= Verbosity::DEBUG->value){ |
|
| 98 | 98 | $row .= $this->renderTrace( |
| 99 | 99 | $exception, |
| 100 | 100 | new Highlighter( |
| 101 | 101 | $this->colorsSupport ? new ConsoleStyle() : new PlainStyle() |
| 102 | 102 | ) |
| 103 | 103 | ); |
| 104 | - } elseif ($verbosity->value >= Verbosity::VERBOSE->value) { |
|
| 104 | + } elseif ($verbosity->value >= Verbosity::VERBOSE->value){ |
|
| 105 | 105 | $row .= $this->renderTrace($exception); |
| 106 | 106 | } |
| 107 | 107 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | $length += $padding; |
| 134 | 134 | |
| 135 | - foreach ($lines as $line) { |
|
| 135 | + foreach ($lines as $line){ |
|
| 136 | 136 | $result .= $this->format( |
| 137 | 137 | "<{$style}>%s%s%s</reset>\n", |
| 138 | 138 | \str_repeat('', $padding + 1), |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | private function renderTrace(\Throwable $e, ?Highlighter $h = null): string |
| 151 | 151 | { |
| 152 | 152 | $stacktrace = $this->getStacktrace($e); |
| 153 | - if (empty($stacktrace)) { |
|
| 153 | + if (empty($stacktrace)){ |
|
| 154 | 154 | return ''; |
| 155 | 155 | } |
| 156 | 156 | |
@@ -159,16 +159,16 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | $pad = \strlen((string)\count($stacktrace)); |
| 161 | 161 | |
| 162 | - foreach ($stacktrace as $i => $trace) { |
|
| 163 | - $file = isset($trace['file']) ? (string) $trace['file'] : null; |
|
| 162 | + foreach ($stacktrace as $i => $trace){ |
|
| 163 | + $file = isset($trace['file']) ? (string)$trace['file'] : null; |
|
| 164 | 164 | $classColor = 'while'; |
| 165 | 165 | |
| 166 | - if ($file !== null) { |
|
| 166 | + if ($file !== null){ |
|
| 167 | 167 | \str_starts_with($file, $rootDir) and $file = \substr($file, \strlen($rootDir) + 1); |
| 168 | 168 | $classColor = \str_starts_with($file, 'vendor/') ? 'gray' : 'white'; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - if (isset($trace['type'], $trace['class'])) { |
|
| 171 | + if (isset($trace['type'], $trace['class'])){ |
|
| 172 | 172 | $line = $this->format( |
| 173 | 173 | "<$classColor>%s.</reset> <white>%s%s%s()</reset>", |
| 174 | 174 | \str_pad((string)((int)$i + 1), $pad, ' ', \STR_PAD_LEFT), |
@@ -176,13 +176,13 @@ discard block |
||
| 176 | 176 | $trace['type'], |
| 177 | 177 | $trace['function'] |
| 178 | 178 | ); |
| 179 | - } else { |
|
| 179 | + }else{ |
|
| 180 | 180 | $line = $this->format( |
| 181 | 181 | ' <white>%s()</reset>', |
| 182 | 182 | $trace['function'] |
| 183 | 183 | ); |
| 184 | 184 | } |
| 185 | - if ($file !== null) { |
|
| 185 | + if ($file !== null){ |
|
| 186 | 186 | $line .= $this->format( |
| 187 | 187 | ' <yellow>at</reset> <green>%s</reset><yellow>:</reset><white>%s</reset>', |
| 188 | 188 | $file, |
@@ -190,21 +190,21 @@ discard block |
||
| 190 | 190 | ); |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - if (\in_array($line, $this->lines, true)) { |
|
| 193 | + if (\in_array($line, $this->lines, true)){ |
|
| 194 | 194 | continue; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | $this->lines[] = $line; |
| 198 | 198 | |
| 199 | - $result .= $line . "\n"; |
|
| 199 | + $result .= $line."\n"; |
|
| 200 | 200 | |
| 201 | - if ($h !== null && !empty($trace['file'])) { |
|
| 201 | + if ($h !== null && !empty($trace['file'])){ |
|
| 202 | 202 | $str = @\file_get_contents($trace['file']); |
| 203 | 203 | $result .= $h->highlightLines( |
| 204 | 204 | $str, |
| 205 | 205 | $trace['line'], |
| 206 | 206 | static::SHOW_LINES |
| 207 | - ) . "\n"; |
|
| 207 | + )."\n"; |
|
| 208 | 208 | unset($str); |
| 209 | 209 | } |
| 210 | 210 | } |
@@ -217,13 +217,13 @@ discard block |
||
| 217 | 217 | */ |
| 218 | 218 | private function format(string $format, mixed ...$args): string |
| 219 | 219 | { |
| 220 | - if (!$this->colorsSupport) { |
|
| 220 | + if (!$this->colorsSupport){ |
|
| 221 | 221 | $format = \preg_replace('/<[^>]+>/', '', $format); |
| 222 | - } else { |
|
| 223 | - $format = \preg_replace_callback('/(<([^>]+)>)/', static function ($partial) { |
|
| 222 | + }else{ |
|
| 223 | + $format = \preg_replace_callback('/(<([^>]+)>)/', static function ($partial){ |
|
| 224 | 224 | $style = ''; |
| 225 | - foreach (\explode(',', \trim($partial[2], '/')) as $color) { |
|
| 226 | - if (isset(self::COLORS[$color])) { |
|
| 225 | + foreach (\explode(',', \trim($partial[2], '/')) as $color){ |
|
| 226 | + if (isset(self::COLORS[$color])){ |
|
| 227 | 227 | $style .= self::COLORS[$color]; |
| 228 | 228 | } |
| 229 | 229 | } |
@@ -242,12 +242,12 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | private function isColorsSupported(mixed $stream = STDOUT): bool |
| 244 | 244 | { |
| 245 | - if ('Hyper' === \getenv('TERM_PROGRAM')) { |
|
| 245 | + if ('Hyper' === \getenv('TERM_PROGRAM')){ |
|
| 246 | 246 | return true; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - try { |
|
| 250 | - if (\DIRECTORY_SEPARATOR === '\\') { |
|
| 249 | + try{ |
|
| 250 | + if (\DIRECTORY_SEPARATOR === '\\'){ |
|
| 251 | 251 | return (\function_exists('sapi_windows_vt100_support') && @\sapi_windows_vt100_support($stream)) |
| 252 | 252 | || \getenv('ANSICON') !== false |
| 253 | 253 | || \getenv('ConEmuANSI') === 'ON' |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | return @\stream_isatty($stream); |
| 258 | - } catch (\Throwable) { |
|
| 258 | + }catch (\Throwable){ |
|
| 259 | 259 | return false; |
| 260 | 260 | } |
| 261 | 261 | } |
@@ -68,7 +68,8 @@ discard block |
||
| 68 | 68 | $exceptions = [$exception]; |
| 69 | 69 | $currentE = $exception; |
| 70 | 70 | |
| 71 | - while ($exception = $exception->getPrevious()) { |
|
| 71 | + while ($exception = $exception->getPrevious()) |
|
| 72 | + { |
|
| 72 | 73 | $exceptions[] = $exception; |
| 73 | 74 | } |
| 74 | 75 | |
@@ -77,7 +78,8 @@ discard block |
||
| 77 | 78 | $result = []; |
| 78 | 79 | $rootDir = \getcwd(); |
| 79 | 80 | |
| 80 | - foreach ($exceptions as $exception) { |
|
| 81 | + foreach ($exceptions as $exception) |
|
| 82 | + { |
|
| 81 | 83 | $prefix = $currentE === $exception ? '' : 'Previous: '; |
| 82 | 84 | $row = $this->renderHeader( |
| 83 | 85 | \sprintf("%s[%s]\n%s", $prefix, $exception::class, $exception->getMessage()), |
@@ -94,14 +96,17 @@ discard block |
||
| 94 | 96 | $exception->getLine() |
| 95 | 97 | ); |
| 96 | 98 | |
| 97 | - if ($verbosity->value >= Verbosity::DEBUG->value) { |
|
| 99 | + if ($verbosity->value >= Verbosity::DEBUG->value) |
|
| 100 | + { |
|
| 98 | 101 | $row .= $this->renderTrace( |
| 99 | 102 | $exception, |
| 100 | 103 | new Highlighter( |
| 101 | 104 | $this->colorsSupport ? new ConsoleStyle() : new PlainStyle() |
| 102 | 105 | ) |
| 103 | 106 | ); |
| 104 | - } elseif ($verbosity->value >= Verbosity::VERBOSE->value) { |
|
| 107 | + } |
|
| 108 | + elseif ($verbosity->value >= Verbosity::VERBOSE->value) |
|
| 109 | + { |
|
| 105 | 110 | $row .= $this->renderTrace($exception); |
| 106 | 111 | } |
| 107 | 112 | |
@@ -132,7 +137,8 @@ discard block |
||
| 132 | 137 | |
| 133 | 138 | $length += $padding; |
| 134 | 139 | |
| 135 | - foreach ($lines as $line) { |
|
| 140 | + foreach ($lines as $line) |
|
| 141 | + { |
|
| 136 | 142 | $result .= $this->format( |
| 137 | 143 | "<{$style}>%s%s%s</reset>\n", |
| 138 | 144 | \str_repeat('', $padding + 1), |
@@ -150,7 +156,8 @@ discard block |
||
| 150 | 156 | private function renderTrace(\Throwable $e, ?Highlighter $h = null): string |
| 151 | 157 | { |
| 152 | 158 | $stacktrace = $this->getStacktrace($e); |
| 153 | - if (empty($stacktrace)) { |
|
| 159 | + if (empty($stacktrace)) |
|
| 160 | + { |
|
| 154 | 161 | return ''; |
| 155 | 162 | } |
| 156 | 163 | |
@@ -159,16 +166,19 @@ discard block |
||
| 159 | 166 | |
| 160 | 167 | $pad = \strlen((string)\count($stacktrace)); |
| 161 | 168 | |
| 162 | - foreach ($stacktrace as $i => $trace) { |
|
| 169 | + foreach ($stacktrace as $i => $trace) |
|
| 170 | + { |
|
| 163 | 171 | $file = isset($trace['file']) ? (string) $trace['file'] : null; |
| 164 | 172 | $classColor = 'while'; |
| 165 | 173 | |
| 166 | - if ($file !== null) { |
|
| 174 | + if ($file !== null) |
|
| 175 | + { |
|
| 167 | 176 | \str_starts_with($file, $rootDir) and $file = \substr($file, \strlen($rootDir) + 1); |
| 168 | 177 | $classColor = \str_starts_with($file, 'vendor/') ? 'gray' : 'white'; |
| 169 | 178 | } |
| 170 | 179 | |
| 171 | - if (isset($trace['type'], $trace['class'])) { |
|
| 180 | + if (isset($trace['type'], $trace['class'])) |
|
| 181 | + { |
|
| 172 | 182 | $line = $this->format( |
| 173 | 183 | "<$classColor>%s.</reset> <white>%s%s%s()</reset>", |
| 174 | 184 | \str_pad((string)((int)$i + 1), $pad, ' ', \STR_PAD_LEFT), |
@@ -176,13 +186,16 @@ discard block |
||
| 176 | 186 | $trace['type'], |
| 177 | 187 | $trace['function'] |
| 178 | 188 | ); |
| 179 | - } else { |
|
| 189 | + } |
|
| 190 | + else |
|
| 191 | + { |
|
| 180 | 192 | $line = $this->format( |
| 181 | 193 | ' <white>%s()</reset>', |
| 182 | 194 | $trace['function'] |
| 183 | 195 | ); |
| 184 | 196 | } |
| 185 | - if ($file !== null) { |
|
| 197 | + if ($file !== null) |
|
| 198 | + { |
|
| 186 | 199 | $line .= $this->format( |
| 187 | 200 | ' <yellow>at</reset> <green>%s</reset><yellow>:</reset><white>%s</reset>', |
| 188 | 201 | $file, |
@@ -190,7 +203,8 @@ discard block |
||
| 190 | 203 | ); |
| 191 | 204 | } |
| 192 | 205 | |
| 193 | - if (\in_array($line, $this->lines, true)) { |
|
| 206 | + if (\in_array($line, $this->lines, true)) |
|
| 207 | + { |
|
| 194 | 208 | continue; |
| 195 | 209 | } |
| 196 | 210 | |
@@ -198,7 +212,8 @@ discard block |
||
| 198 | 212 | |
| 199 | 213 | $result .= $line . "\n"; |
| 200 | 214 | |
| 201 | - if ($h !== null && !empty($trace['file'])) { |
|
| 215 | + if ($h !== null && !empty($trace['file'])) |
|
| 216 | + { |
|
| 202 | 217 | $str = @\file_get_contents($trace['file']); |
| 203 | 218 | $result .= $h->highlightLines( |
| 204 | 219 | $str, |
@@ -217,13 +232,19 @@ discard block |
||
| 217 | 232 | */ |
| 218 | 233 | private function format(string $format, mixed ...$args): string |
| 219 | 234 | { |
| 220 | - if (!$this->colorsSupport) { |
|
| 235 | + if (!$this->colorsSupport) |
|
| 236 | + { |
|
| 221 | 237 | $format = \preg_replace('/<[^>]+>/', '', $format); |
| 222 | - } else { |
|
| 223 | - $format = \preg_replace_callback('/(<([^>]+)>)/', static function ($partial) { |
|
| 238 | + } |
|
| 239 | + else |
|
| 240 | + { |
|
| 241 | + $format = \preg_replace_callback('/(<([^>]+)>)/', static function ($partial) |
|
| 242 | + { |
|
| 224 | 243 | $style = ''; |
| 225 | - foreach (\explode(',', \trim($partial[2], '/')) as $color) { |
|
| 226 | - if (isset(self::COLORS[$color])) { |
|
| 244 | + foreach (\explode(',', \trim($partial[2], '/')) as $color) |
|
| 245 | + { |
|
| 246 | + if (isset(self::COLORS[$color])) |
|
| 247 | + { |
|
| 227 | 248 | $style .= self::COLORS[$color]; |
| 228 | 249 | } |
| 229 | 250 | } |
@@ -242,12 +263,15 @@ discard block |
||
| 242 | 263 | */ |
| 243 | 264 | private function isColorsSupported(mixed $stream = STDOUT): bool |
| 244 | 265 | { |
| 245 | - if ('Hyper' === \getenv('TERM_PROGRAM')) { |
|
| 266 | + if ('Hyper' === \getenv('TERM_PROGRAM')) |
|
| 267 | + { |
|
| 246 | 268 | return true; |
| 247 | 269 | } |
| 248 | 270 | |
| 249 | - try { |
|
| 250 | - if (\DIRECTORY_SEPARATOR === '\\') { |
|
| 271 | + try |
|
| 272 | + { |
|
| 273 | + if (\DIRECTORY_SEPARATOR === '\\') |
|
| 274 | + { |
|
| 251 | 275 | return (\function_exists('sapi_windows_vt100_support') && @\sapi_windows_vt100_support($stream)) |
| 252 | 276 | || \getenv('ANSICON') !== false |
| 253 | 277 | || \getenv('ConEmuANSI') === 'ON' |
@@ -255,7 +279,9 @@ discard block |
||
| 255 | 279 | } |
| 256 | 280 | |
| 257 | 281 | return @\stream_isatty($stream); |
| 258 | - } catch (\Throwable) { |
|
| 282 | + } |
|
| 283 | + catch (\Throwable) |
|
| 284 | + { |
|
| 259 | 285 | return false; |
| 260 | 286 | } |
| 261 | 287 | } |