From e420253093b73b50524e0d938da4800db454cd23 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 16 Apr 2019 17:25:44 +0200 Subject: [PATCH] fixed various small bugs --- src/Environment.php | 1 + src/Extension/CoreExtension.php | 2 +- src/Extension/StringLoaderExtension.php | 4 ++-- src/Loader/FilesystemLoader.php | 2 +- src/Test/IntegrationTestCase.php | 2 +- src/Test/NodeTestCase.php | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Environment.php b/src/Environment.php index 7e89c661a27..2616533d930 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -470,6 +470,7 @@ public function loadClass($cls, $name, $index = null) $this->cache->load($key); } + $source = null; if (!class_exists($cls, false)) { $loader = $this->getLoader(); if (!$loader instanceof SourceContextLoaderInterface) { diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index 71ce3bf2222..37301dfd478 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -1658,7 +1658,7 @@ function twig_constant_is_defined($constant, $object = null) function twig_array_batch($items, $size, $fill = null, $preserveKeys = true) { if (!twig_test_iterable($items)) { - throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($from) ? \get_class($from) : \gettype($from))); + throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items))); } $size = ceil($size); diff --git a/src/Extension/StringLoaderExtension.php b/src/Extension/StringLoaderExtension.php index 295d5911ce1..baeba969e09 100644 --- a/src/Extension/StringLoaderExtension.php +++ b/src/Extension/StringLoaderExtension.php @@ -35,7 +35,7 @@ class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader namespace { use Twig\Environment; -use Twig\Template; +use Twig\TemplateWrapper; /** * Loads a template from a string. @@ -45,7 +45,7 @@ class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader * @param string $template A template as a string or object implementing __toString() * @param string $name An optional name of the template to be used in error messages * - * @return Template + * @return TemplateWrapper */ function twig_template_from_string(Environment $env, $template, $name = null) { diff --git a/src/Loader/FilesystemLoader.php b/src/Loader/FilesystemLoader.php index ae9c979a766..eec160cf799 100644 --- a/src/Loader/FilesystemLoader.php +++ b/src/Loader/FilesystemLoader.php @@ -170,7 +170,7 @@ public function exists($name) } try { - return false !== $this->findTemplate($name, false); + return false !== $this->findTemplate($name); } catch (LoaderError $e) { @trigger_error(sprintf('In %s::findTemplate(), you must accept a second argument that when set to "false" returns "false" instead of throwing an exception. Not supporting this argument is deprecated since version 1.27.', \get_class($this)), E_USER_DEPRECATED); diff --git a/src/Test/IntegrationTestCase.php b/src/Test/IntegrationTestCase.php index d1b633ab947..36b36075867 100644 --- a/src/Test/IntegrationTestCase.php +++ b/src/Test/IntegrationTestCase.php @@ -194,7 +194,7 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e $message = $e->getMessage(); $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $message))); $last = substr($message, \strlen($message) - 1); - $this->assertTrue('.' === $last || '?' === $last, $message, 'Exception message must end with a dot or a question mark.'); + $this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.'); return; } diff --git a/src/Test/NodeTestCase.php b/src/Test/NodeTestCase.php index b35cd21853c..f3358cb9a36 100644 --- a/src/Test/NodeTestCase.php +++ b/src/Test/NodeTestCase.php @@ -56,7 +56,7 @@ protected function getVariableGetter($name, $line = false) $line = $line > 0 ? "// line {$line}\n" : ''; if (\PHP_VERSION_ID >= 70000) { - return sprintf('%s($context["%s"] ?? null)', $line, $name, $name); + return sprintf('%s($context["%s"] ?? null)', $line, $name); } if (\PHP_VERSION_ID >= 50400) {