From 02b8e666755411eb3a45bb106883067d6a6a923d Mon Sep 17 00:00:00 2001 From: Maxime Helias Date: Tue, 8 Oct 2019 17:11:52 +0200 Subject: [PATCH] Replacement of Twig depreciation --- src/Command/GenerateTypesCommand.php | 16 ++++++++++------ src/TypesGenerator.php | 5 +++-- tests/TypesGeneratorTest.php | 3 ++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Command/GenerateTypesCommand.php b/src/Command/GenerateTypesCommand.php index 9f32255f..90341fb4 100644 --- a/src/Command/GenerateTypesCommand.php +++ b/src/Command/GenerateTypesCommand.php @@ -25,6 +25,10 @@ use Symfony\Component\Console\Logger\ConsoleLogger; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Yaml\Parser; +use Twig\Environment; +use Twig\Extension\DebugExtension; +use Twig\Loader\FilesystemLoader; +use Twig\TwigFilter; /** * Generate entities command. @@ -149,14 +153,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int $templatePaths = $processedConfiguration['generatorTemplates']; $templatePaths[] = __DIR__.'/../../templates/'; - $loader = new \Twig_Loader_Filesystem($templatePaths); - $twig = new \Twig_Environment($loader, ['autoescape' => false, 'debug' => $processedConfiguration['debug']]); - $twig->addFilter(new \Twig_SimpleFilter('ucfirst', 'ucfirst')); - $twig->addFilter(new \Twig_SimpleFilter('pluralize', [Inflector::class, 'pluralize'])); - $twig->addFilter(new \Twig_SimpleFilter('singularize', [Inflector::class, 'singularize'])); + $loader = new FilesystemLoader($templatePaths); + $twig = new Environment($loader, ['autoescape' => false, 'debug' => $processedConfiguration['debug']]); + $twig->addFilter(new TwigFilter('ucfirst', 'ucfirst')); + $twig->addFilter(new TwigFilter('pluralize', [Inflector::class, 'pluralize'])); + $twig->addFilter(new TwigFilter('singularize', [Inflector::class, 'singularize'])); if ($processedConfiguration['debug']) { - $twig->addExtension(new \Twig_Extension_Debug()); + $twig->addExtension(new DebugExtension()); } $logger = new ConsoleLogger($output); diff --git a/src/TypesGenerator.php b/src/TypesGenerator.php index a8cf1ab6..13fb1d8e 100644 --- a/src/TypesGenerator.php +++ b/src/TypesGenerator.php @@ -26,6 +26,7 @@ use PhpCsFixer\RuleSet; use PhpCsFixer\Runner\Runner; use Psr\Log\LoggerInterface; +use Twig\Environment; /** * Generates entity files. @@ -57,7 +58,7 @@ class TypesGenerator private const SCHEMA_ORG_SUPERSEDED_BY = 'schema:supersededBy'; /** - * @var \Twig_Environment + * @var Environment */ private $twig; @@ -89,7 +90,7 @@ class TypesGenerator /** * @param \EasyRdf_Graph[] $graphs */ - public function __construct(\Twig_Environment $twig, LoggerInterface $logger, array $graphs, CardinalitiesExtractor $cardinalitiesExtractor, GoodRelationsBridge $goodRelationsBridge) + public function __construct(Environment $twig, LoggerInterface $logger, array $graphs, CardinalitiesExtractor $cardinalitiesExtractor, GoodRelationsBridge $goodRelationsBridge) { if (!$graphs) { throw new \InvalidArgumentException('At least one graph must be injected.'); diff --git a/tests/TypesGeneratorTest.php b/tests/TypesGeneratorTest.php index fecdc2f6..04601020 100644 --- a/tests/TypesGeneratorTest.php +++ b/tests/TypesGeneratorTest.php @@ -20,6 +20,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Psr\Log\NullLogger; +use Twig\Environment; /** * @author Teoh Han Hui @@ -28,7 +29,7 @@ class TypesGeneratorTest extends TestCase { public function testGenerate(): void { - $twigProphecy = $this->prophesize(\Twig_Environment::class); + $twigProphecy = $this->prophesize(Environment::class); foreach ($this->getClasses() as $class) { $twigProphecy->render('class.php.twig', Argument::that($this->getContextMatcher($class)))->willReturn()->shouldBeCalled(); }