You are here

private function LintCommand::getContext in Twig Tweak 3.x

Same name and namespace in other branches
  1. 3.1.x src/Command/LintCommand.php \Drupal\twig_tweak\Command\LintCommand::getContext()
1 call to LintCommand::getContext()
LintCommand::renderException in src/Command/LintCommand.php

File

src/Command/LintCommand.php, line 256

Class

LintCommand
Command that will validate your template syntax and output encountered errors.

Namespace

Drupal\twig_tweak\Command

Code

private function getContext(string $template, int $line, int $context = 3) {
  $lines = explode("\n", $template);
  $position = max(0, $line - $context);
  $max = min(\count($lines), $line - 1 + $context);
  $result = [];
  while ($position < $max) {
    $result[$position + 1] = $lines[$position];
    ++$position;
  }
  return $result;
}