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' => <<