diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 958048f47..caae17b96 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -19,28 +19,6 @@ return (new Config()) 'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'allow_unused_params' => true], ]) - ->setRuleCustomisationPolicy(new class implements PhpCsFixer\Config\RuleCustomisationPolicyInterface { - public function getPolicyVersionForCache(): string - { - return hash_file('xxh128', __FILE__); - } - - public function getRuleCustomisers(): array - { - return [ - 'void_return' => static function (SplFileInfo $file) { - // temporary hack due to bug: https://github.com/symfony/symfony/issues/62734 - if (!$file instanceof Symfony\Component\Finder\SplFileInfo) { - return false; - } - - return !preg_match('#(^|/)tests/#i', $file->getRelativePathname()); - }, - ]; - } - }) ->setRiskyAllowed(true) - // the void_return customiser above is dropped by parallel workers, so run sequentially - ->setParallelConfig(ParallelConfigFactory::sequential()) ->setFinder((new Finder())->in(__DIR__)) ; diff --git a/extra/cache-extra/Tests/FunctionalTest.php b/extra/cache-extra/Tests/FunctionalTest.php index 31bf44971..97bf8cf83 100644 --- a/extra/cache-extra/Tests/FunctionalTest.php +++ b/extra/cache-extra/Tests/FunctionalTest.php @@ -23,7 +23,7 @@ use Twig\RuntimeLoader\RuntimeLoaderInterface; class FunctionalTest extends TestCase { - public function testIsCached() + public function testIsCached(): void { $cache = new ArrayAdapter(); $twig = $this->createEnvironment(['index' => '{% cache "city;v1" %}{{- city -}}{% endcache %}'], $cache); @@ -33,7 +33,7 @@ class FunctionalTest extends TestCase $this->assertSame('Paris', $value); } - public function testTtlNoArgs() + public function testTtlNoArgs(): void { $twig = $this->createEnvironment(['index' => '{% cache "ttl_no_args" ttl() %}{% endcache %}']); $this->expectException(SyntaxError::class); @@ -41,7 +41,7 @@ class FunctionalTest extends TestCase $twig->render('index'); } - public function testTtlTooManyArgs() + public function testTtlTooManyArgs(): void { $twig = $this->createEnvironment(['index' => '{% cache "ttl_too_many_args" ttl(0, 1) %}{% endcache %}']); $this->expectException(SyntaxError::class); @@ -49,7 +49,7 @@ class FunctionalTest extends TestCase $twig->render('index'); } - public function testTagsNoArgs() + public function testTagsNoArgs(): void { $twig = $this->createEnvironment(['index' => '{% cache "tags_no_args" tags() %}{% endcache %}']); $this->expectException(SyntaxError::class); @@ -57,7 +57,7 @@ class FunctionalTest extends TestCase $twig->render('index'); } - public function testTagsTooManyArgs() + public function testTagsTooManyArgs(): void { $twig = $this->createEnvironment(['index' => '{% cache "tags_too_many_args" tags(["foo"], 1) %}{% endcache %}']); $this->expectException(SyntaxError::class); diff --git a/extra/cssinliner-extra/Tests/FunctionalTest.php b/extra/cssinliner-extra/Tests/FunctionalTest.php index 72c152113..b93efd6a1 100644 --- a/extra/cssinliner-extra/Tests/FunctionalTest.php +++ b/extra/cssinliner-extra/Tests/FunctionalTest.php @@ -18,7 +18,7 @@ use Twig\Loader\ArrayLoader; class FunctionalTest extends TestCase { - public function testInlineCssIsNotSafeInJsContext() + public function testInlineCssIsNotSafeInJsContext(): void { $twig = new Environment(new ArrayLoader([ 'index' => "{% autoescape 'js' %}{% apply inline_css %}

x

{% endapply %}{% endautoescape %}", @@ -32,7 +32,7 @@ class FunctionalTest extends TestCase $this->assertMatchesRegularExpression('{\\\\u003[Cc]p\\\\u003[Ee]x\\\\u003[Cc]\\\\/p\\\\u003[Ee]}', $output); } - public function testInlineCssPreEscapesUnsafeInput() + public function testInlineCssPreEscapesUnsafeInput(): void { $twig = new Environment(new ArrayLoader([ 'index' => '{{ payload|inline_css }}', diff --git a/extra/cssinliner-extra/Tests/LegacyFunctionsTest.php b/extra/cssinliner-extra/Tests/LegacyFunctionsTest.php index d62e267fd..4337f4e4f 100644 --- a/extra/cssinliner-extra/Tests/LegacyFunctionsTest.php +++ b/extra/cssinliner-extra/Tests/LegacyFunctionsTest.php @@ -21,7 +21,7 @@ use function Twig\Extra\CssInliner\twig_inline_css; */ class LegacyFunctionsTest extends TestCase { - public function testInlineCss() + public function testInlineCss(): void { $this->assertSame(CssInlinerExtension::inlineCss('

body

', 'p { color: red }'), twig_inline_css('

body

', 'p { color: red }')); } diff --git a/extra/html-extra/Tests/CvaTest.php b/extra/html-extra/Tests/CvaTest.php index b8b32fbef..7f1e45660 100644 --- a/extra/html-extra/Tests/CvaTest.php +++ b/extra/html-extra/Tests/CvaTest.php @@ -19,14 +19,14 @@ class CvaTest extends TestCase /** * @dataProvider recipeProvider */ - public function testRecipes(array $recipe, array $recipes, string $expected) + public function testRecipes(array $recipe, array $recipes, string $expected): void { $recipeClass = new Cva($recipe['base'] ?? '', $recipe['variants'] ?? [], $recipe['compounds'] ?? [], $recipe['defaultVariants'] ?? []); $this->assertEquals($expected, $recipeClass->apply($recipes)); } - public function testApply() + public function testApply(): void { $recipe = new Cva('font-semibold border rounded', [ 'colors' => [ @@ -49,7 +49,7 @@ class CvaTest extends TestCase $this->assertEquals('font-semibold border rounded text-primary text-sm text-red-500', $recipe->apply(['colors' => 'primary', 'sizes' => 'sm'])); } - public function testApplyWithNullString() + public function testApplyWithNullString(): void { $recipe = new Cva('font-semibold border rounded', [ 'colors' => [ @@ -623,7 +623,7 @@ class CvaTest extends TestCase /** * @dataProvider provideAdditionalClassesCases */ - public function testAdditionalClasses(string|array $base, array|string $additionals, string $expected) + public function testAdditionalClasses(string|array $base, array|string $additionals, string $expected): void { $cva = new Cva($base); if (!$additionals) { diff --git a/extra/html-extra/Tests/HtmlAttrMergeTest.php b/extra/html-extra/Tests/HtmlAttrMergeTest.php index d129a5adf..6fa57911f 100644 --- a/extra/html-extra/Tests/HtmlAttrMergeTest.php +++ b/extra/html-extra/Tests/HtmlAttrMergeTest.php @@ -21,7 +21,7 @@ class HtmlAttrMergeTest extends TestCase /** * @dataProvider htmlAttrProvider */ - public function testMerge(array $expected, array $inputs) + public function testMerge(array $expected, array $inputs): void { $result = HtmlExtension::htmlAttrMerge(...$inputs); @@ -180,7 +180,7 @@ class HtmlAttrMergeTest extends TestCase ]; } - public function testIncompatibleValuesMergeThrowsException() + public function testIncompatibleValuesMergeThrowsException(): void { $this->expectException(RuntimeError::class); $this->expectExceptionMessage('Cannot merge incompatible values for key "test"'); diff --git a/extra/html-extra/Tests/HtmlAttrTest.php b/extra/html-extra/Tests/HtmlAttrTest.php index 13bd6694d..bbd7dbd97 100644 --- a/extra/html-extra/Tests/HtmlAttrTest.php +++ b/extra/html-extra/Tests/HtmlAttrTest.php @@ -24,7 +24,7 @@ class HtmlAttrTest extends TestCase /** * @dataProvider htmlAttrProvider */ - public function testPrintingAttributes(string $expected, array $inputs) + public function testPrintingAttributes(string $expected, array $inputs): void { $result = HtmlExtension::htmlAttr(new Environment(new ArrayLoader()), ...$inputs); @@ -285,7 +285,7 @@ class HtmlAttrTest extends TestCase ]; } - public function testIterableObjectCastedToArray() + public function testIterableObjectCastedToArray(): void { /* This test case demonstrates how objects could e. g. implement helper logic @@ -307,7 +307,7 @@ class HtmlAttrTest extends TestCase self::assertSame('data-controller="dropdown tooltip" data-action="click->dropdown#toggle mouseover->tooltip#show"', $result); } - public function testDataAttributeWithNonJsonEncodableValueThrowsRuntimeError() + public function testDataAttributeWithNonJsonEncodableValueThrowsRuntimeError(): void { $this->expectException(RuntimeError::class); $this->expectExceptionMessage('The "data-bad" attribute value cannot be JSON encoded.'); @@ -318,7 +318,7 @@ class HtmlAttrTest extends TestCase ); } - public function testNonStringableObjectAsAttributeValueThrowsRuntimeError() + public function testNonStringableObjectAsAttributeValueThrowsRuntimeError(): void { $this->expectException(RuntimeError::class); $this->expectExceptionMessage('The "title" attribute value should be a scalar, an iterable, or an object implementing "Stringable"'); diff --git a/extra/html-extra/Tests/LegacyFunctionsTest.php b/extra/html-extra/Tests/LegacyFunctionsTest.php index accf8afb3..3f961dad3 100644 --- a/extra/html-extra/Tests/LegacyFunctionsTest.php +++ b/extra/html-extra/Tests/LegacyFunctionsTest.php @@ -19,7 +19,7 @@ use Twig\Extra\Html\HtmlExtension; */ class LegacyFunctionsTest extends TestCase { - public function testHtmlToMarkdown() + public function testHtmlToMarkdown(): void { $this->assertSame(HtmlExtension::htmlClasses(['charset' => 'utf-8']), twig_html_classes(['charset' => 'utf-8'])); } diff --git a/extra/inky-extra/Tests/FunctionalTest.php b/extra/inky-extra/Tests/FunctionalTest.php index abf0c7194..4fbc8104f 100644 --- a/extra/inky-extra/Tests/FunctionalTest.php +++ b/extra/inky-extra/Tests/FunctionalTest.php @@ -18,7 +18,7 @@ use Twig\Loader\ArrayLoader; class FunctionalTest extends TestCase { - public function testInkyToHtmlPreEscapesUnsafeInput() + public function testInkyToHtmlPreEscapesUnsafeInput(): void { $twig = new Environment(new ArrayLoader([ 'index' => '{{ payload|inky_to_html }}', diff --git a/extra/inky-extra/Tests/LegacyFunctionsTest.php b/extra/inky-extra/Tests/LegacyFunctionsTest.php index 4810235b5..42d9c2923 100644 --- a/extra/inky-extra/Tests/LegacyFunctionsTest.php +++ b/extra/inky-extra/Tests/LegacyFunctionsTest.php @@ -21,7 +21,7 @@ use function Twig\Extra\Inky\twig_inky; */ class LegacyFunctionsTest extends TestCase { - public function testInlineCss() + public function testInlineCss(): void { $this->assertSame(InkyExtension::inky('

Foo

'), twig_inky('

Foo

')); } diff --git a/extra/intl-extra/Tests/IntlExtensionTest.php b/extra/intl-extra/Tests/IntlExtensionTest.php index 403efbfa1..e870b7c4f 100644 --- a/extra/intl-extra/Tests/IntlExtensionTest.php +++ b/extra/intl-extra/Tests/IntlExtensionTest.php @@ -19,7 +19,7 @@ use Twig\Loader\ArrayLoader; class IntlExtensionTest extends TestCase { - public function testFormatterWithoutProto() + public function testFormatterWithoutProto(): void { $ext = new IntlExtension(); $env = new Environment(new ArrayLoader()); @@ -31,7 +31,7 @@ class IntlExtensionTest extends TestCase ); } - public function testFormatterWithoutProtoFallsBackToCoreExtensionTimezone() + public function testFormatterWithoutProtoFallsBackToCoreExtensionTimezone(): void { $ext = new IntlExtension(); $env = new Environment(new ArrayLoader()); @@ -45,7 +45,7 @@ class IntlExtensionTest extends TestCase ); } - public function testFormatterWithoutProtoSkipTimezoneConverter() + public function testFormatterWithoutProtoSkipTimezoneConverter(): void { $ext = new IntlExtension(); $env = new Environment(new ArrayLoader()); @@ -59,7 +59,7 @@ class IntlExtensionTest extends TestCase ); } - public function testFormatterProto() + public function testFormatterProto(): void { $dateFormatterProto = new \IntlDateFormatter('fr', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, new \DateTimeZone('Europe/Paris')); $numberFormatterProto = new \NumberFormatter('fr', \NumberFormatter::DECIMAL); @@ -78,7 +78,7 @@ class IntlExtensionTest extends TestCase ); } - public function testFormatterOverridenProto() + public function testFormatterOverridenProto(): void { $dateFormatterProto = new \IntlDateFormatter('fr', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, new \DateTimeZone('Europe/Paris')); $numberFormatterProto = new \NumberFormatter('fr', \NumberFormatter::DECIMAL); @@ -97,7 +97,7 @@ class IntlExtensionTest extends TestCase ); } - public function testDateFormatterCacheIsBounded() + public function testDateFormatterCacheIsBounded(): void { $ext = new IntlExtension(); $env = new Environment(new ArrayLoader()); @@ -115,7 +115,7 @@ class IntlExtensionTest extends TestCase ); } - public function testNumberFormatterCacheIsBounded() + public function testNumberFormatterCacheIsBounded(): void { $ext = new IntlExtension(); diff --git a/extra/markdown-extra/Tests/FunctionalTest.php b/extra/markdown-extra/Tests/FunctionalTest.php index 9d5608253..863221d18 100644 --- a/extra/markdown-extra/Tests/FunctionalTest.php +++ b/extra/markdown-extra/Tests/FunctionalTest.php @@ -28,7 +28,7 @@ class FunctionalTest extends TestCase /** * @dataProvider getMarkdownTests */ - public function testMarkdown(string $template, string $expected) + public function testMarkdown(string $template, string $expected): void { foreach ([LeagueMarkdown::class, ErusevMarkdown::class, /* MichelfMarkdown::class, */ DefaultMarkdown::class] as $class) { $twig = new Environment(new ArrayLoader([ @@ -92,7 +92,7 @@ EOF, "

Paragraph 1

\n+

Paragraph 2

"], /** * @dataProvider getIndentationTests */ - public function testStripsCommonIndentation(string $body, string $expected) + public function testStripsCommonIndentation(string $body, string $expected): void { $runtime = new MarkdownRuntime(new class implements MarkdownInterface { public function convert(string $body): string @@ -117,7 +117,7 @@ EOF, "

Paragraph 1

\n+

Paragraph 2

"], ]; } - public function testMarkdownToHtmlIsNotSafeInJsContext() + public function testMarkdownToHtmlIsNotSafeInJsContext(): void { $twig = new Environment(new ArrayLoader([ 'index' => "{% autoescape 'js' %}{{ '# Hello'|markdown_to_html }}{% endautoescape %}", diff --git a/extra/markdown-extra/Tests/LegacyFunctionsTest.php b/extra/markdown-extra/Tests/LegacyFunctionsTest.php index 19a861de3..5fb5ed360 100644 --- a/extra/markdown-extra/Tests/LegacyFunctionsTest.php +++ b/extra/markdown-extra/Tests/LegacyFunctionsTest.php @@ -22,7 +22,7 @@ use Twig\Extra\Markdown\MarkdownExtension; */ class LegacyFunctionsTest extends TestCase { - public function testHtmlToMarkdown() + public function testHtmlToMarkdown(): void { $this->assertSame(MarkdownExtension::htmlToMarkdown('

foo

'), html_to_markdown('

foo

')); } diff --git a/extra/twig-extra-bundle/DependencyInjection/Compiler/MissingExtensionSuggestorPass.php b/extra/twig-extra-bundle/DependencyInjection/Compiler/MissingExtensionSuggestorPass.php index fdd65820b..7833336bc 100644 --- a/extra/twig-extra-bundle/DependencyInjection/Compiler/MissingExtensionSuggestorPass.php +++ b/extra/twig-extra-bundle/DependencyInjection/Compiler/MissingExtensionSuggestorPass.php @@ -34,8 +34,7 @@ if (!method_exists(ContainerBuilder::class, 'getAutoconfiguredAttributes')) { } else { class MissingExtensionSuggestorPass implements CompilerPassInterface { - /** @return void */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->getParameter('kernel.debug')) { return; diff --git a/extra/twig-extra-bundle/DependencyInjection/TwigExtraExtension.php b/extra/twig-extra-bundle/DependencyInjection/TwigExtraExtension.php index b7f732f90..6de993717 100644 --- a/extra/twig-extra-bundle/DependencyInjection/TwigExtraExtension.php +++ b/extra/twig-extra-bundle/DependencyInjection/TwigExtraExtension.php @@ -31,8 +31,7 @@ if (!method_exists(ContainerBuilder::class, 'getAutoconfiguredAttributes')) { /** @internal */ trait TwigExtraExtensionTrait { - /** @return void */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $this->doLoad($configs, $container); } diff --git a/extra/twig-extra-bundle/Tests/DependencyInjection/TwigExtraExtensionTest.php b/extra/twig-extra-bundle/Tests/DependencyInjection/TwigExtraExtensionTest.php index ce263ac2c..177c6acd3 100644 --- a/extra/twig-extra-bundle/Tests/DependencyInjection/TwigExtraExtensionTest.php +++ b/extra/twig-extra-bundle/Tests/DependencyInjection/TwigExtraExtensionTest.php @@ -20,7 +20,7 @@ use Twig\Extra\TwigExtraBundle\Extensions; class TwigExtraExtensionTest extends TestCase { - public function testDefaultConfiguration() + public function testDefaultConfiguration(): void { $container = new ContainerBuilder(new ParameterBag([ 'kernel.debug' => false, diff --git a/extra/twig-extra-bundle/Tests/IntegrationTest.php b/extra/twig-extra-bundle/Tests/IntegrationTest.php index df62da2da..3d22851c5 100644 --- a/extra/twig-extra-bundle/Tests/IntegrationTest.php +++ b/extra/twig-extra-bundle/Tests/IntegrationTest.php @@ -15,7 +15,7 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; class IntegrationTest extends KernelTestCase { - public function testCommonMarkRendering() + public function testCommonMarkRendering(): void { self::bootKernel(); diff --git a/extra/twig-extra-bundle/TwigExtraBundle.php b/extra/twig-extra-bundle/TwigExtraBundle.php index 495785623..5289e1feb 100644 --- a/extra/twig-extra-bundle/TwigExtraBundle.php +++ b/extra/twig-extra-bundle/TwigExtraBundle.php @@ -29,8 +29,7 @@ if (method_exists(KernelInterface::class, 'getShareDir')) { } else { class TwigExtraBundle extends Bundle { - /** @return void */ - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); diff --git a/src/Environment.php b/src/Environment.php index 71459e210..2d75b0b0a 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -157,7 +157,7 @@ class Environment * * @return void */ - public function enableDebug() + public function enableDebug(): void { $this->debug = true; $this->updateOptionsHash(); @@ -168,7 +168,7 @@ class Environment * * @return void */ - public function disableDebug() + public function disableDebug(): void { $this->debug = false; $this->updateOptionsHash(); @@ -189,7 +189,7 @@ class Environment * * @return void */ - public function enableAutoReload() + public function enableAutoReload(): void { $this->autoReload = true; } @@ -199,7 +199,7 @@ class Environment * * @return void */ - public function disableAutoReload() + public function disableAutoReload(): void { $this->autoReload = false; } @@ -219,7 +219,7 @@ class Environment * * @return void */ - public function enableStrictVariables() + public function enableStrictVariables(): void { $this->strictVariables = true; $this->updateOptionsHash(); @@ -230,7 +230,7 @@ class Environment * * @return void */ - public function disableStrictVariables() + public function disableStrictVariables(): void { $this->strictVariables = false; $this->updateOptionsHash(); @@ -281,7 +281,7 @@ class Environment * * @return void */ - public function setCache($cache) + public function setCache($cache): void { if (\is_string($cache)) { $this->originalCache = $cache; @@ -519,7 +519,7 @@ class Environment /** * @return void */ - public function setLexer(Lexer $lexer) + public function setLexer(Lexer $lexer): void { $this->lexer = $lexer; } @@ -539,7 +539,7 @@ class Environment /** * @return void */ - public function setParser(Parser $parser) + public function setParser(Parser $parser): void { $this->parser = $parser; } @@ -561,7 +561,7 @@ class Environment /** * @return void */ - public function setCompiler(Compiler $compiler) + public function setCompiler(Compiler $compiler): void { $this->compiler = $compiler; } @@ -598,7 +598,7 @@ class Environment /** * @return void */ - public function setLoader(LoaderInterface $loader) + public function setLoader(LoaderInterface $loader): void { $this->loader = $loader; } @@ -611,7 +611,7 @@ class Environment /** * @return void */ - public function setCharset(string $charset) + public function setCharset(string $charset): void { if ('UTF8' === $charset = strtoupper($charset ?: '')) { // iconv on Windows requires "UTF-8" instead of "UTF8" @@ -634,7 +634,7 @@ class Environment /** * @return void */ - public function addRuntimeLoader(RuntimeLoaderInterface $loader) + public function addRuntimeLoader(RuntimeLoaderInterface $loader): void { $this->runtimeLoaders[] = $loader; } @@ -684,7 +684,7 @@ class Environment /** * @return void */ - public function addExtension(ExtensionInterface $extension) + public function addExtension(ExtensionInterface $extension): void { $this->extensionSet->addExtension($extension); $this->updateOptionsHash(); @@ -695,7 +695,7 @@ class Environment * * @return void */ - public function setExtensions(array $extensions) + public function setExtensions(array $extensions): void { $this->extensionSet->setExtensions($extensions); $this->updateOptionsHash(); @@ -712,7 +712,7 @@ class Environment /** * @return void */ - public function addTokenParser(TokenParserInterface $parser) + public function addTokenParser(TokenParserInterface $parser): void { $this->extensionSet->addTokenParser($parser); } @@ -746,7 +746,7 @@ class Environment /** * @return void */ - public function addNodeVisitor(NodeVisitorInterface $visitor) + public function addNodeVisitor(NodeVisitorInterface $visitor): void { $this->extensionSet->addNodeVisitor($visitor); } @@ -764,7 +764,7 @@ class Environment /** * @return void */ - public function addFilter(TwigFilter $filter) + public function addFilter(TwigFilter $filter): void { $this->extensionSet->addFilter($filter); } @@ -804,7 +804,7 @@ class Environment /** * @return void */ - public function addTest(TwigTest $test) + public function addTest(TwigTest $test): void { $this->extensionSet->addTest($test); } @@ -838,7 +838,7 @@ class Environment /** * @return void */ - public function addFunction(TwigFunction $function) + public function addFunction(TwigFunction $function): void { $this->extensionSet->addFunction($function); } @@ -885,7 +885,7 @@ class Environment * * @return void */ - public function addGlobal(string $name, $value) + public function addGlobal(string $name, $value): void { if ($this->extensionSet->isInitialized() && !\array_key_exists($name, $this->getGlobals())) { throw new \LogicException(\sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index 9ef620b6a..e299f1dc6 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -143,7 +143,7 @@ final class CoreExtension extends AbstractExtension * @param string|null $format The default date format string * @param string|null $dateIntervalFormat The default date interval format string */ - public function setDateFormat($format = null, $dateIntervalFormat = null) + public function setDateFormat($format = null, $dateIntervalFormat = null): void { if (null !== $format) { $this->dateFormats[0] = $format; @@ -169,7 +169,7 @@ final class CoreExtension extends AbstractExtension * * @param \DateTimeZone|string $timezone The default timezone string or a \DateTimeZone object */ - public function setTimezone($timezone) + public function setTimezone($timezone): void { $this->timezone = $timezone instanceof \DateTimeZone ? $timezone : new \DateTimeZone($timezone); } @@ -195,7 +195,7 @@ final class CoreExtension extends AbstractExtension * @param string $decimalPoint the character(s) to use for the decimal point * @param string $thousandSep the character(s) to use for the thousands separator */ - public function setNumberFormat($decimal, $decimalPoint, $thousandSep) + public function setNumberFormat($decimal, $decimalPoint, $thousandSep): void { $this->numberFormat = [$decimal, $decimalPoint, $thousandSep]; } @@ -2115,7 +2115,7 @@ final class CoreExtension extends AbstractExtension /** * @internal */ - public static function checkArrow(bool $isSandboxed, $arrow, $thing, $type) + public static function checkArrow(bool $isSandboxed, $arrow, $thing, $type): void { if ($arrow instanceof \Closure) { return; diff --git a/src/Extension/EscaperExtension.php b/src/Extension/EscaperExtension.php index 6d9d1ce24..f666e3fdb 100644 --- a/src/Extension/EscaperExtension.php +++ b/src/Extension/EscaperExtension.php @@ -80,11 +80,9 @@ final class EscaperExtension extends AbstractExtension } /** - * @return void - * * @deprecated since Twig 3.10 */ - public function setEscaperRuntime(EscaperRuntime $escaper) + public function setEscaperRuntime(EscaperRuntime $escaper): void { trigger_deprecation('twig/twig', '3.10', 'The "%s()" method is deprecated and not needed if you are using methods from "Twig\Runtime\EscaperRuntime".', __METHOD__); @@ -132,11 +130,9 @@ final class EscaperExtension extends AbstractExtension * @param string $strategy The strategy name that should be used as a strategy in the escape call * @param callable(Environment, string, string): string $callable A valid PHP callable * - * @return void - * * @deprecated since Twig 3.10 */ - public function setEscaper($strategy, callable $callable) + public function setEscaper($strategy, callable $callable): void { trigger_deprecation('twig/twig', '3.10', 'The "%s()" method is deprecated, use the "Twig\Runtime\EscaperRuntime::setEscaper()" method instead (be warned that Environment is not passed anymore to the callable).', __METHOD__); @@ -165,11 +161,9 @@ final class EscaperExtension extends AbstractExtension } /** - * @return void - * * @deprecated since Twig 3.10 */ - public function setSafeClasses(array $safeClasses = []) + public function setSafeClasses(array $safeClasses = []): void { trigger_deprecation('twig/twig', '3.10', 'The "%s()" method is deprecated, use the "Twig\Runtime\EscaperRuntime::setSafeClasses()" method instead.', __METHOD__); @@ -177,11 +171,9 @@ final class EscaperExtension extends AbstractExtension } /** - * @return void - * * @deprecated since Twig 3.10 */ - public function addSafeClass(string $class, array $strategies) + public function addSafeClass(string $class, array $strategies): void { trigger_deprecation('twig/twig', '3.10', 'The "%s()" method is deprecated, use the "Twig\Runtime\EscaperRuntime::addSafeClass()" method instead.', __METHOD__); diff --git a/src/Extension/ProfilerExtension.php b/src/Extension/ProfilerExtension.php index 43e4a449e..b3ad42cc8 100644 --- a/src/Extension/ProfilerExtension.php +++ b/src/Extension/ProfilerExtension.php @@ -23,19 +23,13 @@ class ProfilerExtension extends AbstractExtension $this->actives[] = $profile; } - /** - * @return void - */ - public function enter(Profile $profile) + public function enter(Profile $profile): void { $this->actives[0]->addProfile($profile); array_unshift($this->actives, $profile); } - /** - * @return void - */ - public function leave(Profile $profile) + public function leave(Profile $profile): void { $profile->leave(); array_shift($this->actives); diff --git a/src/ExtensionSet.php b/src/ExtensionSet.php index 7bb62fa78..aa5568986 100644 --- a/src/ExtensionSet.php +++ b/src/ExtensionSet.php @@ -77,7 +77,7 @@ final class ExtensionSet /** * @return void */ - public function initRuntime() + public function initRuntime(): void { $this->runtimeInitialized = true; } diff --git a/src/Node/CheckSecurityCallNode.php b/src/Node/CheckSecurityCallNode.php index 0667bd0fd..978e54ca3 100644 --- a/src/Node/CheckSecurityCallNode.php +++ b/src/Node/CheckSecurityCallNode.php @@ -23,7 +23,7 @@ class CheckSecurityCallNode extends Node /** * @return void */ - public function compile(Compiler $compiler) + public function compile(Compiler $compiler): void { $compiler ->write("\$this->sandbox = \$this->extensions[SandboxExtension::class];\n") diff --git a/src/Node/Expression/CallExpression.php b/src/Node/Expression/CallExpression.php index ad6d3881a..fdebb6ec3 100644 --- a/src/Node/Expression/CallExpression.php +++ b/src/Node/Expression/CallExpression.php @@ -29,7 +29,7 @@ abstract class CallExpression extends AbstractExpression /** * @return void */ - protected function compileCallable(Compiler $compiler) + protected function compileCallable(Compiler $compiler): void { $twigCallable = $this->getTwigCallable(); $callable = $twigCallable->getCallable(); diff --git a/src/Node/Expression/FunctionExpression.php b/src/Node/Expression/FunctionExpression.php index 5983962dc..179dd2070 100644 --- a/src/Node/Expression/FunctionExpression.php +++ b/src/Node/Expression/FunctionExpression.php @@ -58,7 +58,7 @@ class FunctionExpression extends CallExpression implements SupportDefinedTestInt /** * @return void */ - public function compile(Compiler $compiler) + public function compile(Compiler $compiler): void { $name = $this->getAttribute('name'); if ($this->hasAttribute('twig_callable')) { diff --git a/src/Node/IncludeNode.php b/src/Node/IncludeNode.php index 3adf415e1..6e46e481e 100644 --- a/src/Node/IncludeNode.php +++ b/src/Node/IncludeNode.php @@ -82,7 +82,7 @@ class IncludeNode extends Node implements NodeOutputInterface, CoercesChildrenTo /** * @return void */ - protected function addGetTemplate(Compiler $compiler/* , string $template = '' */) + protected function addGetTemplate(Compiler $compiler/* , string $template = '' */): void { $compiler ->raw('$this->load(') @@ -96,7 +96,7 @@ class IncludeNode extends Node implements NodeOutputInterface, CoercesChildrenTo /** * @return void */ - protected function addTemplateArguments(Compiler $compiler) + protected function addTemplateArguments(Compiler $compiler): void { if (!$this->hasNode('variables')) { $compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]'); diff --git a/src/Node/ModuleNode.php b/src/Node/ModuleNode.php index fd43246f4..13d81c8cd 100644 --- a/src/Node/ModuleNode.php +++ b/src/Node/ModuleNode.php @@ -76,7 +76,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface /** * @return void */ - public function setIndex($index) + public function setIndex($index): void { $this->setAttribute('index', $index); } @@ -99,7 +99,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface /** * @return void */ - protected function compileTemplate(Compiler $compiler) + protected function compileTemplate(Compiler $compiler): void { if (!$this->getAttribute('index')) { $compiler->write('hasNode('parent')) { return; @@ -167,7 +167,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface /** * @return void */ - protected function compileClassHeader(Compiler $compiler) + protected function compileClassHeader(Compiler $compiler): void { $compiler ->write("\n\n") @@ -209,7 +209,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface /** * @return void */ - protected function compileConstructor(Compiler $compiler) + protected function compileConstructor(Compiler $compiler): void { $compiler ->write("public function __construct(Environment \$env)\n", "{\n") @@ -349,7 +349,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface /** * @return void */ - protected function compileDisplay(Compiler $compiler) + protected function compileDisplay(Compiler $compiler): void { $compiler ->write("protected function doDisplay(array \$context, array \$blocks = []): iterable\n", "{\n") @@ -397,7 +397,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface /** * @return void */ - protected function compileClassFooter(Compiler $compiler) + protected function compileClassFooter(Compiler $compiler): void { $compiler ->subcompile($this->getNode('class_end')) @@ -409,7 +409,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface /** * @return void */ - protected function compileMacros(Compiler $compiler) + protected function compileMacros(Compiler $compiler): void { $compiler->subcompile($this->getNode('macros')); } @@ -417,7 +417,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface /** * @return void */ - protected function compileGetTemplateName(Compiler $compiler) + protected function compileGetTemplateName(Compiler $compiler): void { $compiler ->write("/**\n") @@ -436,7 +436,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface /** * @return void */ - protected function compileIsTraitable(Compiler $compiler) + protected function compileIsTraitable(Compiler $compiler): void { // A template can be used as a trait if: // * it has no parent @@ -486,7 +486,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface /** * @return void */ - protected function compileDebugInfo(Compiler $compiler) + protected function compileDebugInfo(Compiler $compiler): void { $compiler ->write("/**\n") @@ -503,7 +503,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface /** * @return void */ - protected function compileGetSourceContext(Compiler $compiler) + protected function compileGetSourceContext(Compiler $compiler): void { $compiler ->write("public function getSourceContext(): Source\n", "{\n") diff --git a/src/Node/Node.php b/src/Node/Node.php index dcf912c21..574067475 100644 --- a/src/Node/Node.php +++ b/src/Node/Node.php @@ -115,7 +115,7 @@ class Node implements \Countable, \IteratorAggregate /** * @return void */ - public function compile(Compiler $compiler) + public function compile(Compiler $compiler): void { foreach ($this->nodes as $node) { $compiler->subcompile($node); diff --git a/src/Node/TypesNode.php b/src/Node/TypesNode.php index a18288083..f933b923d 100644 --- a/src/Node/TypesNode.php +++ b/src/Node/TypesNode.php @@ -33,7 +33,7 @@ class TypesNode extends Node /** * @return void */ - public function compile(Compiler $compiler) + public function compile(Compiler $compiler): void { // Don't compile anything. } diff --git a/src/Parser.php b/src/Parser.php index 5ef1aea8d..7d5b223ab 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -321,7 +321,7 @@ class Parser /** * @return void */ - public function embedTemplate(ModuleNode $template) + public function embedTemplate(ModuleNode $template): void { $template->setIndex(++$this->lastEmbedIndex); @@ -571,7 +571,7 @@ class Parser return $body; } - private function checkPrecedenceDeprecations(ExpressionParserInterface $expressionParser, AbstractExpression $expr) + private function checkPrecedenceDeprecations(ExpressionParserInterface $expressionParser, AbstractExpression $expr): void { $this->expressionRefs[$expr] = $expressionParser; $precedenceChanges = $this->parsers->getPrecedenceChanges(); diff --git a/src/Resources/core.php b/src/Resources/core.php index 80f62cf69..df143d9e9 100644 --- a/src/Resources/core.php +++ b/src/Resources/core.php @@ -536,7 +536,7 @@ function twig_array_every(Environment $env, $array, $arrow) * * @deprecated since Twig 3.9 */ -function twig_check_arrow_in_sandbox(Environment $env, $arrow, $thing, $type) +function twig_check_arrow_in_sandbox(Environment $env, $arrow, $thing, $type): void { trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__); diff --git a/src/Resources/debug.php b/src/Resources/debug.php index a0392ff51..0fd6c7b08 100644 --- a/src/Resources/debug.php +++ b/src/Resources/debug.php @@ -17,7 +17,7 @@ use Twig\Extension\DebugExtension; * * @deprecated since Twig 3.9 */ -function twig_var_dump(Environment $env, $context, ...$vars) +function twig_var_dump(Environment $env, $context, ...$vars): void { trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__); diff --git a/src/Runtime/EscaperRuntime.php b/src/Runtime/EscaperRuntime.php index f4a7023c7..57f116680 100644 --- a/src/Runtime/EscaperRuntime.php +++ b/src/Runtime/EscaperRuntime.php @@ -39,7 +39,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface * * @return void */ - public function setEscaper($strategy, callable $callable) + public function setEscaper($strategy, callable $callable): void { $this->escapers[$strategy] = $callable; } @@ -59,7 +59,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface * * @return void */ - public function setSafeClasses(array $safeClasses = []) + public function setSafeClasses(array $safeClasses = []): void { $this->safeClasses = []; $this->safeLookup = []; @@ -74,7 +74,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface * * @return void */ - public function addSafeClass(string $class, array $strategies) + public function addSafeClass(string $class, array $strategies): void { $class = ltrim($class, '\\'); if (!isset($this->safeClasses[$class])) { diff --git a/src/TemplateWrapper.php b/src/TemplateWrapper.php index 265ce3e1c..e0ce7a51d 100644 --- a/src/TemplateWrapper.php +++ b/src/TemplateWrapper.php @@ -54,7 +54,7 @@ final class TemplateWrapper /** * @return void */ - public function display(array $context = []) + public function display(array $context = []): void { // using func_get_args() allows to not expose the blocks argument // as it should only be used by internal code @@ -82,7 +82,7 @@ final class TemplateWrapper /** * @return void */ - public function displayBlock(string $name, array $context = []) + public function displayBlock(string $name, array $context = []): void { $context += $this->env->getGlobals(); foreach ($this->template->yieldBlock($name, $context) as $data) { diff --git a/src/Test/IntegrationTestCase.php b/src/Test/IntegrationTestCase.php index 749174bdd..c66f4783e 100644 --- a/src/Test/IntegrationTestCase.php +++ b/src/Test/IntegrationTestCase.php @@ -127,7 +127,7 @@ abstract class IntegrationTestCase extends TestCase * @return void */ #[DataProvider('provideTests')] - public function testIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') + public function testIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = ''): void { $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation); } @@ -140,7 +140,7 @@ abstract class IntegrationTestCase extends TestCase * @return void */ #[DataProvider('provideLegacyTests'), Group('legacy')] - public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') + public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = ''): void { $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation); } @@ -230,7 +230,7 @@ abstract class IntegrationTestCase extends TestCase /** * @return void */ - protected function doIntegrationTest($file, $message, $condition, $templateSources, $exception, $outputs, $deprecation = '') + protected function doIntegrationTest($file, $message, $condition, $templateSources, $exception, $outputs, $deprecation = ''): void { if (!$outputs) { // dummy test added by assembleTests() when there is no (legacy) test to run diff --git a/src/Test/NodeTestCase.php b/src/Test/NodeTestCase.php index 3ce58b3bf..39dd3b1ec 100644 --- a/src/Test/NodeTestCase.php +++ b/src/Test/NodeTestCase.php @@ -53,7 +53,7 @@ abstract class NodeTestCase extends TestCase * @return void */ #[DataProvider('provideTests')] - public function testCompile($node, $source, $environment = null, $isPattern = false) + public function testCompile($node, $source, $environment = null, $isPattern = false): void { $this->assertNodeCompilation($source, $node, $environment, $isPattern); } @@ -61,7 +61,7 @@ abstract class NodeTestCase extends TestCase /** * @return void */ - public function assertNodeCompilation($source, Node $node, ?Environment $environment = null, $isPattern = false) + public function assertNodeCompilation($source, Node $node, ?Environment $environment = null, $isPattern = false): void { $compiler = $this->getCompiler($environment); $compiler->compile($node); diff --git a/src/TokenStream.php b/src/TokenStream.php index 2586750fa..d9804e320 100644 --- a/src/TokenStream.php +++ b/src/TokenStream.php @@ -42,7 +42,7 @@ final class TokenStream /** * @return void */ - public function injectTokens(array $tokens) + public function injectTokens(array $tokens): void { $this->tokens = array_merge(\array_slice($this->tokens, 0, $this->current), $tokens, \array_slice($this->tokens, $this->current)); } diff --git a/tests/Cache/ChainTest.php b/tests/Cache/ChainTest.php index a14aa4c85..3a57a5212 100644 --- a/tests/Cache/ChainTest.php +++ b/tests/Cache/ChainTest.php @@ -52,7 +52,7 @@ class ChainTest extends TestCase } } - public function testLoadInA() + public function testLoadInA(): void { $cache = new FilesystemCache($this->directory.'/A'); $key = $cache->generateKey('_test_', $this->className); @@ -70,7 +70,7 @@ class ChainTest extends TestCase $this->assertTrue(class_exists($this->className, false)); } - public function testLoadInB() + public function testLoadInB(): void { $cache = new FilesystemCache($this->directory.'/B'); $key = $cache->generateKey('_test_', $this->className); @@ -88,7 +88,7 @@ class ChainTest extends TestCase $this->assertTrue(class_exists($this->className, false)); } - public function testLoadInBoth() + public function testLoadInBoth(): void { $cache = new FilesystemCache($this->directory.'/A'); $key = $cache->generateKey('_test_', $this->className); @@ -117,7 +117,7 @@ class ChainTest extends TestCase $this->assertTrue(class_exists($this->className, false)); } - public function testLoadMissing() + public function testLoadMissing(): void { $this->assertFalse(class_exists($this->className, false)); @@ -126,7 +126,7 @@ class ChainTest extends TestCase $this->assertFalse(class_exists($this->className, false)); } - public function testWrite() + public function testWrite(): void { $content = $this->generateSource(); @@ -153,7 +153,7 @@ class ChainTest extends TestCase $this->assertSame(file_get_contents($keyB), $content); } - public function testGetTimestampInA() + public function testGetTimestampInA(): void { $cache = new FilesystemCache($this->directory.'/A'); $key = $cache->generateKey('_test_', $this->className); @@ -168,7 +168,7 @@ class ChainTest extends TestCase $this->assertSame(1234567890, $this->cache->getTimestamp($this->key)); } - public function testGetTimestampInB() + public function testGetTimestampInB(): void { $cache = new FilesystemCache($this->directory.'/B'); $key = $cache->generateKey('_test_', $this->className); @@ -183,7 +183,7 @@ class ChainTest extends TestCase $this->assertSame(1234567890, $this->cache->getTimestamp($this->key)); } - public function testGetTimestampInBoth() + public function testGetTimestampInBoth(): void { $cacheA = new FilesystemCache($this->directory.'/A'); $keyA = $cacheA->generateKey('_test_', $this->className); @@ -208,7 +208,7 @@ class ChainTest extends TestCase $this->assertSame(1234567890, $this->cache->getTimestamp($this->key)); } - public function testGetTimestampMissingFile() + public function testGetTimestampMissingFile(): void { $this->assertSame(0, $this->cache->getTimestamp($this->key)); } @@ -217,7 +217,7 @@ class ChainTest extends TestCase * @dataProvider provideInput */ #[DataProvider('provideInput')] - public function testGenerateKey($expected, $input) + public function testGenerateKey($expected, $input): void { $cache = new ChainCache([]); $this->assertSame($expected, $cache->generateKey($input, static::class)); diff --git a/tests/Cache/FilesystemTest.php b/tests/Cache/FilesystemTest.php index 486868d2d..a71e54e4a 100644 --- a/tests/Cache/FilesystemTest.php +++ b/tests/Cache/FilesystemTest.php @@ -46,7 +46,7 @@ class FilesystemTest extends TestCase } } - public function testLoad() + public function testLoad(): void { $key = $this->directory.'/cache/cachefile.php'; @@ -63,7 +63,7 @@ class FilesystemTest extends TestCase $this->assertTrue(class_exists($this->className, false)); } - public function testLoadMissing() + public function testLoadMissing(): void { $key = $this->directory.'/cache/cachefile.php'; @@ -74,7 +74,7 @@ class FilesystemTest extends TestCase $this->assertFalse(class_exists($this->className, false)); } - public function testWrite() + public function testWrite(): void { $key = $this->directory.'/cache/cachefile.php'; $content = $this->generateSource(); @@ -89,7 +89,7 @@ class FilesystemTest extends TestCase $this->assertSame(file_get_contents($key), $content); } - public function testWriteFailMkdir() + public function testWriteFailMkdir(): void { if (\defined('PHP_WINDOWS_VERSION_BUILD')) { $this->markTestSkipped('Read-only directories not possible on Windows.'); @@ -110,7 +110,7 @@ class FilesystemTest extends TestCase $this->cache->write($key, $content); } - public function testWriteFailDirWritable() + public function testWriteFailDirWritable(): void { if (\defined('PHP_WINDOWS_VERSION_BUILD')) { $this->markTestSkipped('Read-only directories not possible on Windows.'); @@ -133,7 +133,7 @@ class FilesystemTest extends TestCase $this->cache->write($key, $content); } - public function testWriteFailWriteFile() + public function testWriteFailWriteFile(): void { $key = $this->directory.'/cache/cachefile.php'; $content = $this->generateSource(); @@ -150,7 +150,7 @@ class FilesystemTest extends TestCase $this->cache->write($key, $content); } - public function testGetTimestamp() + public function testGetTimestamp(): void { $key = $this->directory.'/cache/cachefile.php'; @@ -164,7 +164,7 @@ class FilesystemTest extends TestCase $this->assertSame(1234567890, $this->cache->getTimestamp($key)); } - public function testGetTimestampMissingFile() + public function testGetTimestampMissingFile(): void { $key = $this->directory.'/cache/cachefile.php'; $this->assertSame(0, $this->cache->getTimestamp($key)); @@ -176,7 +176,7 @@ class FilesystemTest extends TestCase * @dataProvider provideDirectories */ #[DataProvider('provideDirectories')] - public function testGenerateKey($expected, $input) + public function testGenerateKey($expected, $input): void { $cache = new FilesystemCache($input); $this->assertMatchesRegularExpression($expected, $cache->generateKey('_test_', static::class)); diff --git a/tests/Cache/ReadOnlyFilesystemTest.php b/tests/Cache/ReadOnlyFilesystemTest.php index 78145c95d..c06ad2c4d 100644 --- a/tests/Cache/ReadOnlyFilesystemTest.php +++ b/tests/Cache/ReadOnlyFilesystemTest.php @@ -46,7 +46,7 @@ class ReadOnlyFilesystemTest extends TestCase } } - public function testLoad() + public function testLoad(): void { $key = $this->directory.'/cache/ro-cachefile.php'; @@ -63,7 +63,7 @@ class ReadOnlyFilesystemTest extends TestCase $this->assertTrue(class_exists($this->className, false)); } - public function testLoadMissing() + public function testLoadMissing(): void { $key = $this->directory.'/cache/cachefile.php'; @@ -74,7 +74,7 @@ class ReadOnlyFilesystemTest extends TestCase $this->assertFalse(class_exists($this->className, false)); } - public function testWrite() + public function testWrite(): void { $key = $this->directory.'/cache/cachefile.php'; $content = $this->generateSource(); @@ -88,7 +88,7 @@ class ReadOnlyFilesystemTest extends TestCase $this->assertFileDoesNotExist($key); } - public function testGetTimestamp() + public function testGetTimestamp(): void { $key = $this->directory.'/cache/cachefile.php'; @@ -102,7 +102,7 @@ class ReadOnlyFilesystemTest extends TestCase $this->assertSame(1234567890, $this->cache->getTimestamp($key)); } - public function testGetTimestampMissingFile() + public function testGetTimestampMissingFile(): void { $key = $this->directory.'/cache/cachefile.php'; $this->assertSame(0, $this->cache->getTimestamp($key)); @@ -114,7 +114,7 @@ class ReadOnlyFilesystemTest extends TestCase * @dataProvider provideDirectories */ #[DataProvider('provideDirectories')] - public function testGenerateKey($expected, $input) + public function testGenerateKey($expected, $input): void { $cache = new ReadOnlyFilesystemCache($input); $this->assertMatchesRegularExpression($expected, $cache->generateKey('_test_', static::class)); diff --git a/tests/CompilerTest.php b/tests/CompilerTest.php index 0416b6260..d3d192552 100644 --- a/tests/CompilerTest.php +++ b/tests/CompilerTest.php @@ -27,7 +27,7 @@ use Twig\Loader\ArrayLoader; class CompilerTest extends TestCase { - public function testStringEncodesSingleQuotesAsHexEscape() + public function testStringEncodesSingleQuotesAsHexEscape(): void { $compiler = new Compiler(new Environment(new ArrayLoader())); @@ -45,7 +45,7 @@ class CompilerTest extends TestCase $this->assertSame("it's \"a\" test", $decoded); } - public function testReprNumericValueWithLocale() + public function testReprNumericValueWithLocale(): void { $compiler = new Compiler(new Environment(new ArrayLoader())); diff --git a/tests/ContainerRuntimeLoaderTest.php b/tests/ContainerRuntimeLoaderTest.php index ae1429257..e3b2a65d7 100644 --- a/tests/ContainerRuntimeLoaderTest.php +++ b/tests/ContainerRuntimeLoaderTest.php @@ -26,7 +26,7 @@ use Twig\RuntimeLoader\ContainerRuntimeLoader; class ContainerRuntimeLoaderTest extends TestCase { - public function testLoad() + public function testLoad(): void { $container = $this->createMock(ContainerInterface::class); $container->expects($this->once())->method('has')->with('stdClass')->willReturn(true); @@ -37,7 +37,7 @@ class ContainerRuntimeLoaderTest extends TestCase $this->assertInstanceOf('stdClass', $loader->load('stdClass')); } - public function testLoadUnknownRuntimeReturnsNull() + public function testLoadUnknownRuntimeReturnsNull(): void { $container = $this->createMock(ContainerInterface::class); $container->expects($this->once())->method('has')->with('Foo'); diff --git a/tests/CustomExtensionTest.php b/tests/CustomExtensionTest.php index 3d3712c71..49136649a 100644 --- a/tests/CustomExtensionTest.php +++ b/tests/CustomExtensionTest.php @@ -35,7 +35,7 @@ class CustomExtensionTest extends TestCase * @dataProvider provideInvalidExtensions */ #[DataProvider('provideInvalidExtensions'), Group('legacy')] - public function testGetInvalidOperators(ExtensionInterface $extension, $expectedExceptionMessage) + public function testGetInvalidOperators(ExtensionInterface $extension, $expectedExceptionMessage): void { $env = new Environment(new ArrayLoader()); $env->addExtension($extension); diff --git a/tests/DeprecatedCallableInfoTest.php b/tests/DeprecatedCallableInfoTest.php index 148717c13..17e3d9427 100644 --- a/tests/DeprecatedCallableInfoTest.php +++ b/tests/DeprecatedCallableInfoTest.php @@ -30,7 +30,7 @@ class DeprecatedCallableInfoTest extends TestCase * @dataProvider provideTestsForTriggerDeprecation */ #[DataProvider('provideTestsForTriggerDeprecation')] - public function testTriggerDeprecation($expected, DeprecatedCallableInfo $info) + public function testTriggerDeprecation($expected, DeprecatedCallableInfo $info): void { $info->setType('function'); $info->setName('foo'); @@ -61,7 +61,7 @@ class DeprecatedCallableInfoTest extends TestCase yield ['Since foo/bar 1.1: Twig Function "foo" is deprecated; use "alt_foo" instead in foo.twig at line 1.', new DeprecatedCallableInfo('foo/bar', '1.1', 'alt_foo')]; } - public function testTriggerDeprecationWithoutFileOrLine() + public function testTriggerDeprecationWithoutFileOrLine(): void { $info = new DeprecatedCallableInfo('foo/bar', '1.1'); $info->setType('function'); diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php index 639147dfa..a4b0bf771 100644 --- a/tests/EnvironmentTest.php +++ b/tests/EnvironmentTest.php @@ -53,7 +53,7 @@ class EnvironmentTest extends TestCase { use ExpectDeprecationTrait; - public function testVersionConstants() + public function testVersionConstants(): void { $version = Environment::VERSION; $exploded = explode('-', $version); @@ -68,7 +68,7 @@ class EnvironmentTest extends TestCase $this->assertEquals(Environment::VERSION_ID, Environment::MAJOR_VERSION * 10000 + Environment::MINOR_VERSION * 100 + Environment::RELEASE_VERSION); } - public function testAutoescapeOption() + public function testAutoescapeOption(): void { $loader = new ArrayLoader([ 'html' => '{{ foo }} {{ foo }}', @@ -90,7 +90,7 @@ class EnvironmentTest extends TestCase return $name; } - public function testGlobals() + public function testGlobals(): void { $loader = $this->createMock(LoaderInterface::class); $loader->expects($this->any())->method('getSourceContext')->willReturn(new Source('', '')); @@ -186,7 +186,7 @@ class EnvironmentTest extends TestCase } } - public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate() + public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate(): void { $cache = new FilesystemCache($dir = sys_get_temp_dir().'/twig'); $options = ['cache' => $cache, 'auto_reload' => false, 'debug' => false]; @@ -221,7 +221,7 @@ class EnvironmentTest extends TestCase FilesystemHelper::removeDir($dir); } - public function testAutoReloadCacheMiss() + public function testAutoReloadCacheMiss(): void { $templateName = __FUNCTION__; $templateContent = __FUNCTION__; @@ -248,7 +248,7 @@ class EnvironmentTest extends TestCase $twig->load($templateName); } - public function testAutoReloadCacheHit() + public function testAutoReloadCacheHit(): void { $templateName = __FUNCTION__; $templateContent = __FUNCTION__; @@ -276,7 +276,7 @@ class EnvironmentTest extends TestCase $twig->load($templateName); } - public function testAutoReloadOutdatedCacheHit() + public function testAutoReloadOutdatedCacheHit(): void { $templateName = __FUNCTION__; $templateContent = __FUNCTION__; @@ -304,7 +304,7 @@ class EnvironmentTest extends TestCase $twig->load($templateName); } - public function testHasGetExtensionByClassName() + public function testHasGetExtensionByClassName(): void { $twig = new Environment(new ArrayLoader()); $twig->addExtension($ext = new EnvironmentTest_Extension()); @@ -312,7 +312,7 @@ class EnvironmentTest extends TestCase $this->assertSame($ext, $twig->getExtension(EnvironmentTest_Extension::class)); } - public function testAddExtension() + public function testAddExtension(): void { $twig = new Environment(new ArrayLoader()); $twig->addExtension(new EnvironmentTest_Extension()); @@ -334,7 +334,7 @@ class EnvironmentTest extends TestCase $this->assertTrue($found); } - public function testAddMockExtension() + public function testAddMockExtension(): void { $extension = $this->createMock(ExtensionInterface::class); $loader = new ArrayLoader(['page' => 'hey']); @@ -346,7 +346,7 @@ class EnvironmentTest extends TestCase $this->assertTrue($twig->isTemplateFresh('page', time())); } - public function testOverrideExtension() + public function testOverrideExtension(): void { $twig = new Environment(new ArrayLoader()); $twig->addExtension(new EnvironmentTest_Extension()); @@ -357,7 +357,7 @@ class EnvironmentTest extends TestCase $twig->addExtension(new EnvironmentTest_Extension()); } - public function testAddRuntimeLoader() + public function testAddRuntimeLoader(): void { $runtimeLoader = $this->createMock(RuntimeLoaderInterface::class); $runtimeLoader->expects($this->any())->method('load')->willReturn(new EnvironmentTest_Runtime()); @@ -383,7 +383,7 @@ class EnvironmentTest extends TestCase $this->assertEquals('foo', $twig->render('func_string_named_args')); } - public function testFailLoadTemplate() + public function testFailLoadTemplate(): void { $template = 'testFailLoadTemplate.twig'; $twig = new Environment(new ArrayLoader([$template => false])); @@ -394,7 +394,7 @@ class EnvironmentTest extends TestCase $twig->loadTemplate($twig->getTemplateClass($template), $template, 112233); } - public function testUndefinedFunctionCallback() + public function testUndefinedFunctionCallback(): void { $twig = new Environment(new ArrayLoader()); $twig->registerUndefinedFunctionCallback(static function (string $name) { @@ -410,7 +410,7 @@ class EnvironmentTest extends TestCase $this->assertSame('dynamic', $function->getName()); } - public function testUndefinedFilterCallback() + public function testUndefinedFilterCallback(): void { $twig = new Environment(new ArrayLoader()); $twig->registerUndefinedFilterCallback(static function (string $name) { @@ -426,7 +426,7 @@ class EnvironmentTest extends TestCase $this->assertSame('dynamic', $filter->getName()); } - public function testUndefinedTestCallback() + public function testUndefinedTestCallback(): void { $twig = new Environment(new ArrayLoader()); $twig->registerUndefinedTestCallback(static function (string $name) { @@ -442,7 +442,7 @@ class EnvironmentTest extends TestCase $this->assertSame('dynamic', $test->getName()); } - public function testUndefinedTokenParserCallback() + public function testUndefinedTokenParserCallback(): void { $twig = new Environment(new ArrayLoader()); $twig->registerUndefinedTokenParserCallback(function (string $name) { @@ -465,7 +465,7 @@ class EnvironmentTest extends TestCase * @group legacy */ #[Group('legacy')] - public function testLegacyEchoingNode() + public function testLegacyEchoingNode(): void { $loader = new ArrayLoader(['echo_bar' => 'A{% set v %}B{% test %}C{% endset %}D{% test %}E{{ v }}F{% set w %}{% test %}{% endset %}G{{ w }}H']); @@ -501,7 +501,7 @@ EOF return $loader; } - public function testResettingGlobals() + public function testResettingGlobals(): void { $twig = new Environment(new ArrayLoader(['index' => ''])); $twig->addExtension(new class extends AbstractExtension implements GlobalsInterface { @@ -528,7 +528,7 @@ EOF $this->assertNotSame($g3['global_ext'], $g2['global_ext']); } - public function testHotCache() + public function testHotCache(): void { $dir = sys_get_temp_dir().'/twig-hot-cache-test'; if (is_dir($dir)) { @@ -693,7 +693,7 @@ class EnvironmentTest_Runtime class EnvironmentTest_LegacyEchoingNode extends Node { - public function compile($compiler) + public function compile($compiler): void { $compiler ->addDebugInfo($this) diff --git a/tests/ErrorTest.php b/tests/ErrorTest.php index c9adeaea0..5ec565a7f 100644 --- a/tests/ErrorTest.php +++ b/tests/ErrorTest.php @@ -39,7 +39,7 @@ use Twig\TokenParser\AbstractTokenParser; class ErrorTest extends TestCase { - public function testErrorWithObjectFilename() + public function testErrorWithObjectFilename(): void { $error = new Error('foo'); $error->setSourceContext(new Source('', new \SplFileInfo(__FILE__))); @@ -47,7 +47,7 @@ class ErrorTest extends TestCase $this->assertStringContainsString('tests'.\DIRECTORY_SEPARATOR.'ErrorTest.php', $error->getMessage()); } - public function testTwigExceptionGuessWithMissingVarAndArrayLoader() + public function testTwigExceptionGuessWithMissingVarAndArrayLoader(): void { $loader = new ArrayLoader([ 'base.html' => '{% block content %}{% endblock %}', @@ -76,7 +76,7 @@ EOHTML, } } - public function testTwigExceptionGuessWithExceptionAndArrayLoader() + public function testTwigExceptionGuessWithExceptionAndArrayLoader(): void { $loader = new ArrayLoader([ 'base.html' => '{% block content %}{% endblock %}', @@ -104,7 +104,7 @@ EOHTML, } } - public function testTwigExceptionGuessWithMissingVarAndFilesystemLoader() + public function testTwigExceptionGuessWithMissingVarAndFilesystemLoader(): void { $loader = new FilesystemLoader(__DIR__.'/Fixtures/errors'); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); @@ -123,7 +123,7 @@ EOHTML, } } - public function testTwigExceptionGuessWithExceptionAndFilesystemLoader() + public function testTwigExceptionGuessWithExceptionAndFilesystemLoader(): void { $loader = new FilesystemLoader(__DIR__.'/Fixtures/errors'); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); @@ -146,7 +146,7 @@ EOHTML, * @dataProvider getErroredTemplates */ #[DataProvider('getErroredTemplates')] - public function testTwigExceptionAddsFileAndLine($templates, $name, $line) + public function testTwigExceptionAddsFileAndLine($templates, $name, $line): void { $loader = new ArrayLoader($templates); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); @@ -174,7 +174,7 @@ EOHTML, } } - public function testTwigArrayFilterThrowsRuntimeExceptions() + public function testTwigArrayFilterThrowsRuntimeExceptions(): void { $loader = new ArrayLoader([ 'filter-null.html' => << << << "\n\n\n\n{{ foo() }}", @@ -275,7 +275,7 @@ EOHTML, * @dataProvider getErrorWithoutLineAndContextData */ #[DataProvider('getErrorWithoutLineAndContextData')] - public function testErrorWithoutLineAndContext(LoaderInterface $loader, bool $debug, bool $addDebugInfo, bool $exceptionWithLineAndContext, int $errorLine) + public function testErrorWithoutLineAndContext(LoaderInterface $loader, bool $debug, bool $addDebugInfo, bool $exceptionWithLineAndContext, int $errorLine): void { $twig = new Environment($loader, ['debug' => $debug, 'cache' => false]); $twig->removeCache('no_line_and_context_exception.twig'); @@ -455,7 +455,7 @@ EOHTML, ]; } - public function testErrorFromArrayLoader() + public function testErrorFromArrayLoader(): void { $templates = [ 'index.twig' => '{% include "include.twig" %}', @@ -478,7 +478,7 @@ EOHTML, } } - public function testErrorFromFilesystemLoader() + public function testErrorFromFilesystemLoader(): void { $twig = new Environment(new FilesystemLoader([$dir = __DIR__.'/Fixtures/errors/extends']), ['debug' => true, 'cache' => false]); $include = file_get_contents($dir.'/include.twig'); @@ -496,7 +496,7 @@ EOHTML, class ErrorTest_Foo { - public function bar() + public function bar(): void { throw new \Exception('Runtime error...'); } diff --git a/tests/ExpressionParserTest.php b/tests/ExpressionParserTest.php index b48f8d613..4ce9a5d1e 100644 --- a/tests/ExpressionParserTest.php +++ b/tests/ExpressionParserTest.php @@ -59,7 +59,7 @@ class ExpressionParserTest extends TestCase * @dataProvider getFailingTestsForAssignment */ #[DataProvider('getFailingTestsForAssignment')] - public function testCanOnlyAssignToNames($template) + public function testCanOnlyAssignToNames($template): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); @@ -90,7 +90,7 @@ class ExpressionParserTest extends TestCase * @dataProvider getTestsForSequence */ #[DataProvider('getTestsForSequence')] - public function testSequenceExpression($template, $expected) + public function testSequenceExpression($template, $expected): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $stream = $env->tokenize($source = new Source($template, '')); @@ -104,7 +104,7 @@ class ExpressionParserTest extends TestCase * @dataProvider getFailingTestsForSequence */ #[DataProvider('getFailingTestsForSequence')] - public function testSequenceSyntaxError($template) + public function testSequenceSyntaxError($template): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); @@ -230,7 +230,7 @@ class ExpressionParserTest extends TestCase ]; } - public function testStringExpressionDoesNotConcatenateTwoConsecutiveStrings() + public function testStringExpressionDoesNotConcatenateTwoConsecutiveStrings(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); $stream = $env->tokenize(new Source('{{ "a" "b" }}', 'index')); @@ -240,7 +240,7 @@ class ExpressionParserTest extends TestCase $parser->parse($stream); } - public function testSequenceCompilationError() + public function testSequenceCompilationError(): void { $env = new Environment(new ArrayLoader(['index' => '{{ [1,,2] }}']), ['cache' => false, 'autoescape' => false]); @@ -253,7 +253,7 @@ class ExpressionParserTest extends TestCase * @dataProvider getTestsForString */ #[DataProvider('getTestsForString')] - public function testStringExpression($template, $expected) + public function testStringExpression($template, $expected): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); $stream = $env->tokenize($source = new Source($template, '')); @@ -311,7 +311,7 @@ class ExpressionParserTest extends TestCase * @dataProvider getTestsForNullSafeOperator */ #[DataProvider('getTestsForNullSafeOperator')] - public function testNullSafeOperator($template, $data, $expected) + public function testNullSafeOperator($template, $data, $expected): void { $env = new Environment(new ArrayLoader(['template' => $template]), ['strict_variables' => true]); @@ -384,7 +384,7 @@ class ExpressionParserTest extends TestCase * @dataProvider getTestForInvalidNullSafeOperatorShortCircuiting */ #[DataProvider('getTestForInvalidNullSafeOperatorShortCircuiting')] - public function testInvalidNullSafeOperatorShortCircuiting(string $template, array $data, string $expectedMessage) + public function testInvalidNullSafeOperatorShortCircuiting(string $template, array $data, string $expectedMessage): void { $env = new Environment(new ArrayLoader(['template' => $template]), ['strict_variables' => true]); @@ -408,7 +408,7 @@ class ExpressionParserTest extends TestCase ]; } - public function testMacroDefinitionDoesNotSupportNonNameVariableName() + public function testMacroDefinitionDoesNotSupportNonNameVariableName(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); @@ -423,7 +423,7 @@ class ExpressionParserTest extends TestCase * @dataProvider getMacroDefinitionDoesNotSupportNonConstantDefaultValues */ #[DataProvider('getMacroDefinitionDoesNotSupportNonConstantDefaultValues')] - public function testMacroDefinitionDoesNotSupportNonConstantDefaultValues($template) + public function testMacroDefinitionDoesNotSupportNonConstantDefaultValues($template): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); @@ -446,7 +446,7 @@ class ExpressionParserTest extends TestCase * @dataProvider getMacroDefinitionSupportsConstantDefaultValues */ #[DataProvider('getMacroDefinitionSupportsConstantDefaultValues')] - public function testMacroDefinitionSupportsConstantDefaultValues($template) + public function testMacroDefinitionSupportsConstantDefaultValues($template): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); @@ -471,7 +471,7 @@ class ExpressionParserTest extends TestCase ]; } - public function testUnknownFunction() + public function testUnknownFunction(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); @@ -482,7 +482,7 @@ class ExpressionParserTest extends TestCase $parser->parse($env->tokenize(new Source('{{ cycl() }}', 'index'))); } - public function testUnknownFunctionWithoutSuggestions() + public function testUnknownFunctionWithoutSuggestions(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); @@ -493,7 +493,7 @@ class ExpressionParserTest extends TestCase $parser->parse($env->tokenize(new Source('{{ foobar() }}', 'index'))); } - public function testUnknownFilter() + public function testUnknownFilter(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); @@ -504,7 +504,7 @@ class ExpressionParserTest extends TestCase $parser->parse($env->tokenize(new Source('{{ 1|lowe }}', 'index'))); } - public function testUnknownFilterWithoutSuggestions() + public function testUnknownFilterWithoutSuggestions(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); @@ -515,7 +515,7 @@ class ExpressionParserTest extends TestCase $parser->parse($env->tokenize(new Source('{{ 1|foobar }}', 'index'))); } - public function testUnknownTest() + public function testUnknownTest(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); @@ -527,7 +527,7 @@ class ExpressionParserTest extends TestCase $parser->parse($stream); } - public function testUnknownTestWithoutSuggestions() + public function testUnknownTestWithoutSuggestions(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); @@ -538,7 +538,7 @@ class ExpressionParserTest extends TestCase $parser->parse($env->tokenize(new Source('{{ 1 is foobar }}', 'index'))); } - public function testCompiledCodeForDynamicTest() + public function testCompiledCodeForDynamicTest(): void { $env = new Environment(new ArrayLoader(['index' => '{{ "a" is foo_foo_bar_bar }}']), ['cache' => false, 'autoescape' => false]); $env->addExtension(new class extends AbstractExtension { @@ -553,7 +553,7 @@ class ExpressionParserTest extends TestCase $this->assertStringContainsString('$this->env->getTest(\'*_foo_*_bar\')->getCallable()("foo", "bar", "a")', $env->compile($env->parse($env->tokenize(new Source($env->getLoader()->getSourceContext('index')->getCode(), 'index'))))); } - public function testCompiledCodeForDynamicFunction() + public function testCompiledCodeForDynamicFunction(): void { $env = new Environment(new ArrayLoader(['index' => '{{ foo_foo_bar_bar("a") }}']), ['cache' => false, 'autoescape' => false]); $env->addExtension(new class extends AbstractExtension { @@ -568,7 +568,7 @@ class ExpressionParserTest extends TestCase $this->assertStringContainsString('$this->env->getFunction(\'*_foo_*_bar\')->getCallable()("foo", "bar", "a")', $env->compile($env->parse($env->tokenize(new Source($env->getLoader()->getSourceContext('index')->getCode(), 'index'))))); } - public function testCompiledCodeForDynamicFilter() + public function testCompiledCodeForDynamicFilter(): void { $env = new Environment(new ArrayLoader(['index' => '{{ "a"|foo_foo_bar_bar }}']), ['cache' => false, 'autoescape' => false]); $env->addExtension(new class extends AbstractExtension { @@ -583,7 +583,7 @@ class ExpressionParserTest extends TestCase $this->assertStringContainsString('$this->env->getFilter(\'*_foo_*_bar\')->getCallable()("foo", "bar", "a")', $env->compile($env->parse($env->tokenize(new Source($env->getLoader()->getSourceContext('index')->getCode(), 'index'))))); } - public function testNotReadyFunctionWithNoConstructor() + public function testNotReadyFunctionWithNoConstructor(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $env->addFunction(new TwigFunction('foo', 'foo', ['node_class' => NotReadyFunctionExpressionWithNoConstructor::class])); @@ -593,7 +593,7 @@ class ExpressionParserTest extends TestCase $this->expectNotToPerformAssertions(); } - public function testNotReadyFilterWithNoConstructor() + public function testNotReadyFilterWithNoConstructor(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $env->addFilter(new TwigFilter('foo', 'foo', ['node_class' => NotReadyFilterExpressionWithNoConstructor::class])); @@ -603,7 +603,7 @@ class ExpressionParserTest extends TestCase $this->expectNotToPerformAssertions(); } - public function testNotReadyTestWithNoConstructor() + public function testNotReadyTestWithNoConstructor(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $env->addTest(new TwigTest('foo', 'foo', ['node_class' => NotReadyTestExpressionWithNoConstructor::class])); @@ -617,7 +617,7 @@ class ExpressionParserTest extends TestCase * @group legacy */ #[Group('legacy')] - public function testNotReadyFunction() + public function testNotReadyFunction(): void { $this->expectDeprecation('Since twig/twig 3.12: Twig node "Twig\Tests\NotReadyFunctionExpression" is not marked as ready for passing a "TwigFunction" in the constructor instead of its name; please update your code and then add #[FirstClassTwigCallableReady] attribute to the constructor.'); $this->expectDeprecation('Since twig/twig 3.12: Not passing an instance of "TwigFunction" when creating a "foo" function of type "Twig\Tests\NotReadyFunctionExpression" is deprecated.'); @@ -633,7 +633,7 @@ class ExpressionParserTest extends TestCase * @group legacy */ #[Group('legacy')] - public function testNotReadyFilter() + public function testNotReadyFilter(): void { $this->expectDeprecation('Since twig/twig 3.12: Twig node "Twig\Tests\NotReadyFilterExpression" is not marked as ready for passing a "TwigFilter" in the constructor instead of its name; please update your code and then add #[FirstClassTwigCallableReady] attribute to the constructor.'); $this->expectDeprecation('Since twig/twig 3.12: Not passing an instance of "TwigFilter" when creating a "foo" filter of type "Twig\Tests\NotReadyFilterExpression" is deprecated.'); @@ -649,7 +649,7 @@ class ExpressionParserTest extends TestCase * @group legacy */ #[Group('legacy')] - public function testNotReadyTest() + public function testNotReadyTest(): void { $this->expectDeprecation('Since twig/twig 3.12: Twig node "Twig\Tests\NotReadyTestExpression" is not marked as ready for passing a "TwigTest" in the constructor instead of its name; please update your code and then add #[FirstClassTwigCallableReady] attribute to the constructor.'); $this->expectDeprecation('Since twig/twig 3.12: Not passing an instance of "TwigTest" when creating a "foo" test of type "Twig\Tests\NotReadyTestExpression" is deprecated.'); @@ -661,7 +661,7 @@ class ExpressionParserTest extends TestCase $parser->parse($env->tokenize(new Source('{{ 1 is foo }}', 'index'))); } - public function testReadyFunction() + public function testReadyFunction(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $env->addFunction(new TwigFunction('foo', 'foo', ['node_class' => ReadyFunctionExpression::class])); @@ -671,7 +671,7 @@ class ExpressionParserTest extends TestCase $this->expectNotToPerformAssertions(); } - public function testReadyFilter() + public function testReadyFilter(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $env->addFilter(new TwigFilter('foo', 'foo', ['node_class' => ReadyFilterExpression::class])); @@ -681,7 +681,7 @@ class ExpressionParserTest extends TestCase $this->expectNotToPerformAssertions(); } - public function testReadyTest() + public function testReadyTest(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $env->addTest(new TwigTest('foo', 'foo', ['node_class' => ReadyTestExpression::class])); @@ -691,7 +691,7 @@ class ExpressionParserTest extends TestCase $this->expectNotToPerformAssertions(); } - public function testTwoWordTestPrecedence() + public function testTwoWordTestPrecedence(): void { // a "empty element" test must have precedence over "empty" $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); @@ -702,7 +702,7 @@ class ExpressionParserTest extends TestCase $this->expectNotToPerformAssertions(); } - public function testUnaryPrecedenceChange() + public function testUnaryPrecedenceChange(): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); $env->addExtension(new class extends AbstractExtension { @@ -730,7 +730,7 @@ class ExpressionParserTest extends TestCase * @dataProvider getBindingPowerTests */ #[DataProvider('getBindingPowerTests')] - public function testBindingPower(string $expression, string $expectedExpression, mixed $expectedResult, array $context = []) + public function testBindingPower(string $expression, string $expectedExpression, mixed $expectedResult, array $context = []): void { $env = new Environment(new ArrayLoader([ 'expression' => $expression, @@ -814,7 +814,7 @@ class ExpressionParserTest extends TestCase yield '= stronger than ternary' => ['{% do c = 4 ? 0 : -1 %}{{ c }}', '{% do c = (4 ? 0 : -1) %}{{ c }}', eval('return 4 ? 0 : -1;')]; } - public function testLiteralExpressionParserGetOperatorTokensReturnsEmptyArray() + public function testLiteralExpressionParserGetOperatorTokensReturnsEmptyArray(): void { $env = new Environment(new ArrayLoader()); $parser = $env->getExpressionParsers()->getByClass(LiteralExpressionParser::class); @@ -823,7 +823,7 @@ class ExpressionParserTest extends TestCase $this->assertSame('literal', $parser->getName()); } - public function testExpressionParserGetOperatorTokensDefaultBehavior() + public function testExpressionParserGetOperatorTokensDefaultBehavior(): void { $env = new Environment(new ArrayLoader()); @@ -836,7 +836,7 @@ class ExpressionParserTest extends TestCase } } - public function testLiteralIsNotRegisteredAsOperator() + public function testLiteralIsNotRegisteredAsOperator(): void { // Ensure "literal" is not in the operator registry $env = new Environment(new ArrayLoader()); diff --git a/tests/Extension/AttributeExtensionTest.php b/tests/Extension/AttributeExtensionTest.php index c5d9ddd39..b7b3decd0 100644 --- a/tests/Extension/AttributeExtensionTest.php +++ b/tests/Extension/AttributeExtensionTest.php @@ -30,7 +30,7 @@ class AttributeExtensionTest extends TestCase * @dataProvider provideFilters */ #[DataProvider('provideFilters')] - public function testFilter(string $name, string $method, array $options) + public function testFilter(string $name, string $method, array $options): void { $extension = new AttributeExtension(ExtensionWithAttributes::class); foreach ($extension->getFilters() as $filter) { @@ -62,7 +62,7 @@ class AttributeExtensionTest extends TestCase * @dataProvider provideFunctions */ #[DataProvider('provideFunctions')] - public function testFunction(string $name, string $method, array $options) + public function testFunction(string $name, string $method, array $options): void { $extension = new AttributeExtension(ExtensionWithAttributes::class); foreach ($extension->getFunctions() as $function) { @@ -94,7 +94,7 @@ class AttributeExtensionTest extends TestCase * @dataProvider provideTests */ #[DataProvider('provideTests')] - public function testTest(string $name, string $method, array $options) + public function testTest(string $name, string $method, array $options): void { $extension = new AttributeExtension(ExtensionWithAttributes::class); foreach ($extension->getTests() as $test) { @@ -121,7 +121,7 @@ class AttributeExtensionTest extends TestCase yield 'deprecated positional' => ['deprecated_positional_test', 'deprecatedPositionalTest', ['deprecation_info' => new DeprecatedCallableInfo('foo/bar', '1.2')]]; } - public function testFilterRequireOneArgument() + public function testFilterRequireOneArgument(): void { $extension = new AttributeExtension(FilterWithoutValue::class); @@ -131,7 +131,7 @@ class AttributeExtensionTest extends TestCase $extension->getTests(); } - public function testTestRequireOneArgument() + public function testTestRequireOneArgument(): void { $extension = new AttributeExtension(TestWithoutValue::class); @@ -141,14 +141,14 @@ class AttributeExtensionTest extends TestCase $extension->getTests(); } - public function testLastModifiedWithObject() + public function testLastModifiedWithObject(): void { $extension = new AttributeExtension(\stdClass::class); $this->assertSame(filemtime((new \ReflectionClass(AttributeExtension::class))->getFileName()), $extension->getLastModified()); } - public function testLastModifiedWithClass() + public function testLastModifiedWithClass(): void { $extension = new AttributeExtension('__CLASS_FOR_TEST_LAST_MODIFIED__'); @@ -163,7 +163,7 @@ class AttributeExtensionTest extends TestCase } } - public function testMultipleRegistrations() + public function testMultipleRegistrations(): void { $extensionSet = new ExtensionSet(); $extensionSet->addExtension($extension1 = new AttributeExtension(ExtensionWithAttributes::class)); diff --git a/tests/Extension/CoreTest.php b/tests/Extension/CoreTest.php index faada348a..57fc0ef92 100644 --- a/tests/Extension/CoreTest.php +++ b/tests/Extension/CoreTest.php @@ -41,7 +41,7 @@ class CoreTest extends TestCase * @dataProvider provideCycleCases */ #[DataProvider('provideCycleCases')] - public function testCycleFunction($values, $position, $expected) + public function testCycleFunction($values, $position, $expected): void { $this->assertSame($expected, CoreExtension::cycle($values, $position)); } @@ -65,7 +65,7 @@ class CoreTest extends TestCase * @dataProvider provideCycleInvalidCases */ #[DataProvider('provideCycleInvalidCases')] - public function testCycleFunctionThrowRuntimeError($values, mixed $position = null) + public function testCycleFunctionThrowRuntimeError($values, mixed $position = null): void { $this->expectException(RuntimeError::class); CoreExtension::cycle($values, $position ?? 0); @@ -84,7 +84,7 @@ class CoreTest extends TestCase * @dataProvider getRandomFunctionTestData */ #[DataProvider('getRandomFunctionTestData')] - public function testRandomFunction(array $expectedInArray, $value1, $value2 = null) + public function testRandomFunction(array $expectedInArray, $value1, $value2 = null): void { for ($i = 0; $i < 100; ++$i) { $this->assertTrue(\in_array(CoreExtension::random('UTF-8', $value1, $value2), $expectedInArray, true)); // assertContains() would not consider the type @@ -140,7 +140,7 @@ class CoreTest extends TestCase ]; } - public function testRandomFunctionWithoutParameter() + public function testRandomFunctionWithoutParameter(): void { $max = mt_getrandmax(); @@ -150,7 +150,7 @@ class CoreTest extends TestCase } } - public function testRandomFunctionReturnsAsIs() + public function testRandomFunctionReturnsAsIs(): void { $this->assertSame('', CoreExtension::random('UTF-8', '')); @@ -158,13 +158,13 @@ class CoreTest extends TestCase $this->assertSame($instance, CoreExtension::random('UTF-8', $instance)); } - public function testRandomFunctionOfEmptyArrayThrowsException() + public function testRandomFunctionOfEmptyArrayThrowsException(): void { $this->expectException(RuntimeError::class); CoreExtension::random('UTF-8', []); } - public function testRandomFunctionOnNonUTF8String() + public function testRandomFunctionOnNonUTF8String(): void { $text = iconv('UTF-8', 'ISO-8859-1', 'Äé'); for ($i = 0; $i < 30; ++$i) { @@ -173,7 +173,7 @@ class CoreTest extends TestCase } } - public function testReverseFilterOnNonUTF8String() + public function testReverseFilterOnNonUTF8String(): void { $input = iconv('UTF-8', 'ISO-8859-1', 'Äé'); $output = iconv('ISO-8859-1', 'UTF-8', CoreExtension::reverse('ISO-8859-1', $input)); @@ -185,7 +185,7 @@ class CoreTest extends TestCase * @dataProvider provideTwigFirstCases */ #[DataProvider('provideTwigFirstCases')] - public function testTwigFirst($expected, $input) + public function testTwigFirst($expected, $input): void { $this->assertSame($expected, CoreExtension::first('UTF-8', $input)); } @@ -207,7 +207,7 @@ class CoreTest extends TestCase * @dataProvider provideTwigLastCases */ #[DataProvider('provideTwigLastCases')] - public function testTwigLast($expected, $input) + public function testTwigLast($expected, $input): void { $this->assertSame($expected, CoreExtension::last('UTF-8', $input)); } @@ -229,7 +229,7 @@ class CoreTest extends TestCase * @dataProvider provideArrayKeyCases */ #[DataProvider('provideArrayKeyCases')] - public function testArrayKeysFilter(array $expected, $input) + public function testArrayKeysFilter(array $expected, $input): void { $this->assertSame($expected, CoreExtension::keys($input)); } @@ -253,7 +253,7 @@ class CoreTest extends TestCase * @dataProvider provideInFilterCases */ #[DataProvider('provideInFilterCases')] - public function testInFilter($expected, $value, $compare) + public function testInFilter($expected, $value, $compare): void { $this->assertSame($expected, CoreExtension::inFilter($value, $compare)); } @@ -282,7 +282,7 @@ class CoreTest extends TestCase * @dataProvider provideSliceFilterCases */ #[DataProvider('provideSliceFilterCases')] - public function testSliceFilter($expected, $input, $start, $length = null, $preserveKeys = false) + public function testSliceFilter($expected, $input, $start, $length = null, $preserveKeys = false): void { $this->assertSame($expected, CoreExtension::slice('UTF-8', $input, $start, $length, $preserveKeys)); } @@ -312,13 +312,13 @@ class CoreTest extends TestCase * @dataProvider provideCompareCases */ #[DataProvider('provideCompareCases')] - public function testCompare($expected, $a, $b) + public function testCompare($expected, $a, $b): void { $this->assertSame($expected, CoreExtension::compare($a, $b)); $this->assertSame($expected, -CoreExtension::compare($b, $a)); } - public function testCompareNAN() + public function testCompareNAN(): void { $this->assertSame(1, CoreExtension::compare(\NAN, 'NAN')); $this->assertSame(1, CoreExtension::compare('NAN', \NAN)); @@ -384,7 +384,7 @@ class CoreTest extends TestCase ]; } - public function testSandboxedInclude() + public function testSandboxedInclude(): void { $twig = new Environment(new ArrayLoader([ 'index' => '{{ include("included", sandboxed: true) }}', @@ -399,7 +399,7 @@ class CoreTest extends TestCase $twig->render('index'); } - public function testSandboxedIncludeWithPreloadedTemplate() + public function testSandboxedIncludeWithPreloadedTemplate(): void { $twig = new Environment(new ArrayLoader([ 'index' => '{{ include("included", sandboxed: true) }}', @@ -418,7 +418,7 @@ class CoreTest extends TestCase $twig->render('index'); } - public function testSandboxedIncludeResultStaysEscapedWhenAssigned() + public function testSandboxedIncludeResultStaysEscapedWhenAssigned(): void { $twig = new Environment(new ArrayLoader([ 'index' => "{% set body = include('included', sandboxed: true) %}[{{ body }}]", @@ -429,7 +429,7 @@ class CoreTest extends TestCase $this->assertSame('[<script>]', $twig->render('index', ['evil' => '