Skip to content

Commit

Permalink
Get the code from the Twig\Source object when handling linter errors (
Browse files Browse the repository at this point in the history
  • Loading branch information
kblais authored Jun 23, 2020
1 parent 3b2068a commit 2592023
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Command/Lint.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Finder\Finder;
use Twig\Error\Error;
use Twig\Error\LoaderError;
use Twig\Source;

/**
* Artisan command to check the syntax of Twig templates.
Expand Down Expand Up @@ -329,15 +330,15 @@ protected function renderException(array $info)
/**
* Grabs the surrounding lines around the exception.
*
* @param string $template Contents of Twig template.
* @param string|int $line Line where the exception occurred.
* @param int $context Number of lines around the line where the exception occurred.
* @param \Twig\Source $template Contents of Twig template.
* @param string|int $line Line where the exception occurred.
* @param int $context Number of lines around the line where the exception occurred.
*
* @return array
*/
protected function getContext($template, $line, $context = 3)
protected function getContext(Source $template, $line, $context = 3)
{
$lines = explode("\n", $template);
$lines = explode("\n", $template->getCode());
$position = max(0, $line - $context);
$max = min(count($lines), $line - 1 + $context);

Expand Down

0 comments on commit 2592023

Please sign in to comment.