From e688f201a1dc9ffa4da35e9fa9370f750b069b46 Mon Sep 17 00:00:00 2001
From: Oliver Klee <typo3-coding@oliverklee.de>
Date: Thu, 9 Mar 2023 23:00:24 +0100
Subject: [PATCH] [TASK] Use native types for internal Fluid classes and
 methods
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Also fix some types as needed.

Resolves: #100134
Releases: main
Change-Id: I87cebe0a3a7e3cb97a9a1802640ed856d7939f39
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78085
Reviewed-by: Nikita Hovratov <nikita.h@live.de>
Tested-by: Markus Klein <markus.klein@typo3.org>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Nikita Hovratov <nikita.h@live.de>
---
 Build/phpstan/phpstan-baseline.neon           |  5 ---
 .../Classes/Core/Cache/FluidTemplateCache.php | 12 +++----
 .../ViewHelper/ViewHelperResolverFactory.php  |  8 ++---
 .../Classes/View/AbstractTemplateView.php     |  6 ++--
 .../fluid/Classes/View/TemplatePaths.php      | 32 ++++++-------------
 5 files changed, 18 insertions(+), 45 deletions(-)

diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon
index 665f28f45934..b953e3eedd39 100644
--- a/Build/phpstan/phpstan-baseline.neon
+++ b/Build/phpstan/phpstan-baseline.neon
@@ -2130,11 +2130,6 @@ parameters:
 			count: 1
 			path: ../../typo3/sysext/fluid/Classes/View/StandaloneView.php
 
-		-
-			message: "#^Method TYPO3\\\\CMS\\\\Fluid\\\\View\\\\TemplatePaths\\:\\:ensureAbsolutePath\\(\\) should return string but returns array\\.$#"
-			count: 1
-			path: ../../typo3/sysext/fluid/Classes/View/TemplatePaths.php
-
 		-
 			message: "#^Method TYPO3\\\\CMS\\\\Fluid\\\\ViewHelpers\\\\Be\\\\Menus\\\\ActionMenuViewHelper\\:\\:compile\\(\\) should return string but returns null\\.$#"
 			count: 1
diff --git a/typo3/sysext/fluid/Classes/Core/Cache/FluidTemplateCache.php b/typo3/sysext/fluid/Classes/Core/Cache/FluidTemplateCache.php
index 83ad0cd7541e..af81e8546eb9 100644
--- a/typo3/sysext/fluid/Classes/Core/Cache/FluidTemplateCache.php
+++ b/typo3/sysext/fluid/Classes/Core/Cache/FluidTemplateCache.php
@@ -34,16 +34,15 @@ class FluidTemplateCache extends PhpFrontend implements FluidCacheInterface
     /**
      * @param null $name
      */
-    public function flush($name = null)
+    public function flush($name = null): void
     {
         parent::flush();
     }
 
     /**
      * @param string $entryIdentifier
-     * @return mixed
      */
-    public function get($entryIdentifier)
+    public function get($entryIdentifier): mixed
     {
         return $this->requireOnce($entryIdentifier);
     }
@@ -54,7 +53,7 @@ class FluidTemplateCache extends PhpFrontend implements FluidCacheInterface
      * @param int $lifetime
      * @throws InvalidDataException
      */
-    public function set($entryIdentifier, $sourceCode, array $tags = [], $lifetime = null)
+    public function set($entryIdentifier, $sourceCode, array $tags = [], $lifetime = null): void
     {
         if (str_starts_with($sourceCode, '<?php')) {
             // Remove opening PHP tag; it is added by the cache backend to which
@@ -64,10 +63,7 @@ class FluidTemplateCache extends PhpFrontend implements FluidCacheInterface
         parent::set($entryIdentifier, $sourceCode, $tags, time() + 86400);
     }
 
-    /**
-     * @return FluidCacheWarmerInterface
-     */
-    public function getCacheWarmer()
+    public function getCacheWarmer(): FluidCacheWarmerInterface
     {
         return new StandardCacheWarmer();
     }
diff --git a/typo3/sysext/fluid/Classes/Core/ViewHelper/ViewHelperResolverFactory.php b/typo3/sysext/fluid/Classes/Core/ViewHelper/ViewHelperResolverFactory.php
index c5e0a05b6198..b7a97b561c58 100644
--- a/typo3/sysext/fluid/Classes/Core/ViewHelper/ViewHelperResolverFactory.php
+++ b/typo3/sysext/fluid/Classes/Core/ViewHelper/ViewHelperResolverFactory.php
@@ -35,12 +35,8 @@ use Psr\Container\ContainerInterface;
  */
 final class ViewHelperResolverFactory implements ViewHelperResolverFactoryInterface
 {
-    private ContainerInterface $container;
-
-    public function __construct(
-        ContainerInterface $container
-    ) {
-        $this->container = $container;
+    public function __construct(private readonly ContainerInterface $container)
+    {
     }
 
     public function create(): ViewHelperResolver
diff --git a/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php b/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php
index 7b74e292da7a..0f510f83522c 100644
--- a/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php
+++ b/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php
@@ -29,10 +29,9 @@ use TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException;
 abstract class AbstractTemplateView extends Typo3FluidAbstractTemplateView
 {
     /**
-     * @param RenderingContextInterface|null $context
      * @internal
      */
-    public function __construct(RenderingContextInterface $context = null)
+    public function __construct(?RenderingContextInterface $context = null)
     {
         if (!$context) {
             $context = GeneralUtility::makeInstance(RenderingContextFactory::class)->create();
@@ -41,10 +40,9 @@ abstract class AbstractTemplateView extends Typo3FluidAbstractTemplateView
     }
 
     /**
-     * @param string $templateName
      * @internal
      */
-    public function setTemplate($templateName)
+    public function setTemplate(string $templateName): void
     {
         $this->baseRenderingContext->setControllerAction($templateName);
     }
diff --git a/typo3/sysext/fluid/Classes/View/TemplatePaths.php b/typo3/sysext/fluid/Classes/View/TemplatePaths.php
index d04870eb00b3..7798cbc36d0e 100644
--- a/typo3/sysext/fluid/Classes/View/TemplatePaths.php
+++ b/typo3/sysext/fluid/Classes/View/TemplatePaths.php
@@ -45,11 +45,7 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
      */
     protected $templatePathAndFilename;
 
-    /**
-     * @param string $extensionKey
-     * @return string|null
-     */
-    protected function getExtensionPrivateResourcesPath($extensionKey)
+    protected function getExtensionPrivateResourcesPath(string $extensionKey): ?string
     {
         $extensionKey = trim($extensionKey);
         if ($extensionKey && ExtensionManagementUtility::isLoaded($extensionKey)) {
@@ -58,19 +54,12 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
         return null;
     }
 
-    /**
-     * @return ConfigurationManager
-     */
-    protected function getConfigurationManager()
+    protected function getConfigurationManager(): ConfigurationManagerInterface
     {
         return GeneralUtility::makeInstance(ConfigurationManager::class);
     }
 
-    /**
-     * @param string $extensionKey
-     * @return array
-     */
-    protected function getContextSpecificViewConfiguration($extensionKey)
+    protected function getContextSpecificViewConfiguration(string $extensionKey): array
     {
         if (empty($extensionKey)) {
             return [];
@@ -123,7 +112,7 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
      *
      * @param string $packageName
      */
-    public function fillDefaultsByPackageName($packageName)
+    public function fillDefaultsByPackageName($packageName): void
     {
         $this->fillFromConfigurationArray($this->getContextSpecificViewConfiguration($packageName));
     }
@@ -131,7 +120,7 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
     /**
      * Overridden setter with enforced sorting behavior
      */
-    public function setTemplateRootPaths(array $templateRootPaths)
+    public function setTemplateRootPaths(array $templateRootPaths): void
     {
         parent::setTemplateRootPaths(
             ArrayUtility::sortArrayWithIntegerKeys($templateRootPaths)
@@ -141,7 +130,7 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
     /**
      * Overridden setter with enforced sorting behavior
      */
-    public function setLayoutRootPaths(array $layoutRootPaths)
+    public function setLayoutRootPaths(array $layoutRootPaths): void
     {
         parent::setLayoutRootPaths(
             ArrayUtility::sortArrayWithIntegerKeys($layoutRootPaths)
@@ -151,7 +140,7 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
     /**
      * Overridden setter with enforced sorting behavior
      */
-    public function setPartialRootPaths(array $partialRootPaths)
+    public function setPartialRootPaths(array $partialRootPaths): void
     {
         parent::setPartialRootPaths(
             ArrayUtility::sortArrayWithIntegerKeys($partialRootPaths)
@@ -163,7 +152,7 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
      *
      * @return string Returns the absolute path to a Fluid template file
      */
-    public function getTemplatePathAndFilename()
+    public function getTemplatePathAndFilename(): string
     {
         return $this->templatePathAndFilename;
     }
@@ -174,10 +163,9 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
      * relative path or a FILE: or EXT: reference
      * but cannot be a FAL resource identifier.
      *
-     * @param mixed $reference
-     * @return string
+     * @param string|array $reference
      */
-    protected function ensureAbsolutePath($reference)
+    protected function ensureAbsolutePath($reference): array|string
     {
         if (!is_array($reference)) {
             return PathUtility::isAbsolutePath($reference) ? $reference : GeneralUtility::getFileAbsFileName($reference);
-- 
GitLab