Skip to content

Commit 91afa52

Browse files
🐛 Multiple bugFix
1 parent 514a2c3 commit 91afa52

File tree

7 files changed

+26
-10
lines changed

7 files changed

+26
-10
lines changed

TwigCS/src/Report/TextFormatter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ public function display(Report $report, string $level = null): void
104104
}
105105

106106
/**
107-
* @param string $template
108-
* @param int $line
109-
* @param int $context
107+
* @param string $template
108+
* @param int|null $line
109+
* @param int $context
110110
*
111111
* @return array
112112
*/
113-
protected function getContext(string $template, int $line, int $context): array
113+
protected function getContext(string $template, ?int $line, int $context): array
114114
{
115115
$lines = explode("\n", $template);
116116

TwigCS/src/Runner/Fixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function fixFile(string $file): bool
145145
try {
146146
$twigSource = new Source($contents, 'TwigCS');
147147
$stream = $this->tokenizer->tokenize($twigSource);
148-
} catch (Exception $e) {
148+
} catch (Exception $exception) {
149149
return false;
150150
}
151151

TwigCS/src/Runner/Linter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ protected function processTemplate(string $file, Ruleset $ruleset, Report $repor
140140
// Tokenizer.
141141
try {
142142
$stream = $this->tokenizer->tokenize($twigSource);
143-
} catch (Exception $e) {
143+
} catch (Exception $exception) {
144144
$sniffViolation = new SniffViolation(
145145
Report::MESSAGE_TYPE_FATAL,
146-
sprintf('Unable to tokenize file: %s', $e->getMessage()),
146+
sprintf('Unable to tokenize file: %s', $exception->getMessage()),
147147
$file
148148
);
149149

TwigCS/src/Token/Tokenizer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,11 @@ protected function lexPunctuation(): void
705705
array_pop($this->bracketsAndTernary);
706706
$lastBracket = end($this->bracketsAndTernary);
707707
} while ('?' === $lastBracket[0]);
708+
709+
// This is maybe the end of the variable, start again.
710+
$this->lexVariable();
711+
712+
return;
708713
}
709714
}
710715

TwigCS/tests/Ruleset/AbstractSniffTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ protected function checkSniff(SniffInterface $sniff, array $expects): void
4949

5050
$ruleset->addSniff($sniff);
5151
$report = $linter->run([$file], $ruleset);
52-
} catch (Exception $e) {
53-
self::fail($e->getMessage());
52+
} catch (Exception $exception) {
53+
self::fail($exception->getMessage());
5454

5555
return;
5656
}

TwigCS/tests/Token/Tokenizer/TokenizerTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,17 @@ public function tokenizeDataProvider(): array
175175
75 => Token::WHITESPACE_TYPE,
176176
76 => Token::BLOCK_END_TYPE,
177177
77 => Token::EOL_TYPE,
178-
78 => Token::EOF_TYPE,
178+
78 => Token::VAR_START_TYPE,
179+
79 => Token::WHITESPACE_TYPE,
180+
80 => Token::NAME_TYPE,
181+
81 => Token::WHITESPACE_TYPE,
182+
82 => Token::OPERATOR_TYPE,
183+
83 => Token::WHITESPACE_TYPE,
184+
84 => Token::STRING_TYPE,
185+
85 => Token::WHITESPACE_TYPE,
186+
86 => Token::VAR_END_TYPE,
187+
87 => Token::EOL_TYPE,
188+
88 => Token::EOF_TYPE,
179189
],
180190
],
181191
[

TwigCS/tests/Token/Tokenizer/TokenizerTest3.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
{{ bar ? 'string' : "string#" }}
33
{{ baz ?: { a:[1, 2] } }}
44
{% set a={foo: bar ? baz ? 1, test: 1} %}
5+
{{ a ? ',' }}

0 commit comments

Comments
 (0)