Skip to content

Commit 2592023

Browse files
authored
Get the code from the Twig\Source object when handling linter errors (#364)
1 parent 3b2068a commit 2592023

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Command/Lint.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Finder\Finder;
2020
use Twig\Error\Error;
2121
use Twig\Error\LoaderError;
22+
use Twig\Source;
2223

2324
/**
2425
* Artisan command to check the syntax of Twig templates.
@@ -329,15 +330,15 @@ protected function renderException(array $info)
329330
/**
330331
* Grabs the surrounding lines around the exception.
331332
*
332-
* @param string $template Contents of Twig template.
333-
* @param string|int $line Line where the exception occurred.
334-
* @param int $context Number of lines around the line where the exception occurred.
333+
* @param \Twig\Source $template Contents of Twig template.
334+
* @param string|int $line Line where the exception occurred.
335+
* @param int $context Number of lines around the line where the exception occurred.
335336
*
336337
* @return array
337338
*/
338-
protected function getContext($template, $line, $context = 3)
339+
protected function getContext(Source $template, $line, $context = 3)
339340
{
340-
$lines = explode("\n", $template);
341+
$lines = explode("\n", $template->getCode());
341342
$position = max(0, $line - $context);
342343
$max = min(count($lines), $line - 1 + $context);
343344

0 commit comments

Comments
 (0)