From 175ea8f37bf002f08b047243b3b7750d89e54501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Dorn?= Date: Tue, 4 Oct 2022 22:48:35 +0200 Subject: [PATCH] formats --- src/Tin.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Tin.php b/src/Tin.php index 98d580b..151c59b 100644 --- a/src/Tin.php +++ b/src/Tin.php @@ -23,8 +23,8 @@ public function highlight(string $code): string "\e[38;2;%sm%s | \e[0m", $this->theme->comment, str_pad( - (string)$line, - strlen((string)$lineCount), + (string) $line, + strlen((string) $lineCount), ' ', STR_PAD_LEFT )); @@ -35,9 +35,9 @@ public function highlight(string $code): string public function process(string $code, callable $transformer): string { - $code = rtrim(str_replace(["\r\n", "\r"], "\n", $code)); + $code = rtrim(str_replace(["\r\n", "\r"], "\n", $code)); $highlighted = array_fill(1, substr_count($code, PHP_EOL) + 1, []); - $tokens = $this->tokenize($code); + $tokens = $this->tokenize($code); $inAttribute = false; foreach ($tokens as $index => $token) { @@ -45,7 +45,7 @@ public function process(string $code, callable $transformer): string if ($token->text === ':' && $tokens[$index - 1]->id === T_NAMED_PARAMETER) { $token->id = T_NAMED_PARAMETER; } elseif ($inAttribute && $token->text === ']' && ($tokens[$index + 1]->id === T_WHITESPACE || $tokens[$index + 1]->id === T_ATTRIBUTE)) { - $token->id = T_ATTRIBUTE_END; + $token->id = T_ATTRIBUTE_END; $inAttribute = false; } elseif ($token->id === T_ATTRIBUTE) { $inAttribute = true; @@ -82,8 +82,8 @@ public function process(string $code, callable $transformer): string array_keys($highlighted), function (string $_, int|string $line) use ($transformer, $highlighted) { $line = $transformer( - (int)$line, - $highlighted[(int)$line], + (int) $line, + $highlighted[(int) $line], count($highlighted), $this->theme ); @@ -96,12 +96,12 @@ function (string $_, int|string $line) use ($transformer, $highlighted) { private function tokenize(string $code): array { - $tokens = Token::tokenize($code); + $tokens = Token::tokenize($code); $indexed = []; - $line = 1; + $line = 1; foreach ($tokens as $token) { - $splits = explode("\n", $token->text); + $splits = explode("\n", $token->text); $newLines = count($splits) - 1; foreach ($splits as $split) { @@ -141,17 +141,17 @@ protected function idFromContext(array $tokens, int $index): int return T_NAMED_PARAMETER; } - $behind = $this->lookBehind($tokens, $index - 1); + $behind = $this->lookBehind($tokens, $index - 1); $twoBehind = $this->lookBehind($tokens, $index - 2); return match ($behind->id) { T_NEW, T_USE, T_PRIVATE, T_PROTECTED, T_PUBLIC, T_NAMESPACE, T_CLASS, T_INTERFACE, T_TRAIT, T_EXTENDS, T_IMPLEMENTS, T_INSTEADOF, 58, 124, 63, 44 => T_CLASS_NAME, - T_FUNCTION => $twoBehind->is([T_PRIVATE, T_PROTECTED, T_PUBLIC, T_STATIC]) ? T_METHOD_NAME : T_FUNCTION_DECL, + T_FUNCTION => $twoBehind->is([T_PRIVATE, T_PROTECTED, T_PUBLIC, T_STATIC]) ? T_METHOD_NAME : T_FUNCTION_DECL, T_OBJECT_OPERATOR => $ahead->text === '(' ? T_METHOD_NAME : T_VARIABLE, - T_DOUBLE_COLON => $ahead->text === '(' || $ahead->id === T_INSTEADOF || $ahead->id === T_AS ? T_METHOD_NAME : T_CONST_NAME, - T_AS => T_METHOD_NAME, - T_ATTRIBUTE => T_ATTRIBUTE_CLASS, - default => (function () use ($ahead, $twoBehind, $tokens, $index) { + T_DOUBLE_COLON => $ahead->text === '(' || $ahead->id === T_INSTEADOF || $ahead->id === T_AS ? T_METHOD_NAME : T_CONST_NAME, + T_AS => T_METHOD_NAME, + T_ATTRIBUTE => T_ATTRIBUTE_CLASS, + default => (function () use ($ahead, $twoBehind, $tokens, $index) { if ($ahead->text === '(') { return T_FUNCTION_NAME; }