From cf61be1b44f7ea9fac6c66753ba0153c5e4f722f Mon Sep 17 00:00:00 2001
From: Alexander Schnitzler <git@alexanderschnitzler.de>
Date: Mon, 11 May 2020 17:33:41 +0200
Subject: [PATCH] [TASK] Fix phpstan checkFunctionArgumentTypes errors in
 ext:core Page

This patch fixes incompatible type usage in function arguments
and is preparatory work for introducing native type hints and
strict mode in all core files.

Releases: master, 10.4
Resolves: #92271
Change-Id: Ia8ba882db3129ad42785d5d39b49a31d2f81b27b
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65657
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../sysext/core/Classes/Page/PageRenderer.php | 21 ++++++++++++-------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/typo3/sysext/core/Classes/Page/PageRenderer.php b/typo3/sysext/core/Classes/Page/PageRenderer.php
index 46a5c34c5d32..856c09dcacb5 100644
--- a/typo3/sysext/core/Classes/Page/PageRenderer.php
+++ b/typo3/sysext/core/Classes/Page/PageRenderer.php
@@ -23,6 +23,8 @@ use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Localization\Locales;
 use TYPO3\CMS\Core\Localization\LocalizationFactory;
 use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;
+use TYPO3\CMS\Core\Package\Package;
+use TYPO3\CMS\Core\Package\PackageInterface;
 use TYPO3\CMS\Core\Package\PackageManager;
 use TYPO3\CMS\Core\Resource\RelativeCssPathFixer;
 use TYPO3\CMS\Core\Resource\ResourceCompressor;
@@ -104,7 +106,7 @@ class PageRenderer implements SingletonInterface
 
     // Arrays containing associative array for the included files
     /**
-     * @var array
+     * @var array<string, array>
      */
     protected $jsFiles = [];
 
@@ -124,12 +126,12 @@ class PageRenderer implements SingletonInterface
     protected $jsFooterLibs = [];
 
     /**
-     * @var array
+     * @var array<string, array>
      */
     protected $cssFiles = [];
 
     /**
-     * @var array
+     * @var array<string, array>
      */
     protected $cssLibs = [];
 
@@ -225,7 +227,7 @@ class PageRenderer implements SingletonInterface
 
     // Static inline code blocks
     /**
-     * @var array
+     * @var array<string, array>
      */
     protected $jsInline = [];
 
@@ -235,7 +237,7 @@ class PageRenderer implements SingletonInterface
     protected $jsFooterInline = [];
 
     /**
-     * @var array
+     * @var array<string, array>
      */
     protected $cssInline = [];
 
@@ -1348,7 +1350,7 @@ class PageRenderer implements SingletonInterface
      * resource folders plus some additional generic configuration.
      *
      * @param bool $isDevelopment
-     * @param array $packages
+     * @param array<string, PackageInterface> $packages
      * @return array The RequireJS configuration
      */
     protected function computeRequireJsConfig($isDevelopment, array $packages)
@@ -1931,7 +1933,7 @@ class PageRenderer implements SingletonInterface
     {
         $templateFile = GeneralUtility::getFileAbsFileName($this->templateFile);
         if (is_file($templateFile)) {
-            $template = file_get_contents($templateFile);
+            $template = (string)file_get_contents($templateFile);
             if ($this->removeLineBreaksFromTemplate) {
                 $template = strtr($template, [LF => '', CR => '']);
             }
@@ -2545,7 +2547,7 @@ class PageRenderer implements SingletonInterface
         if (strpos($file, 'EXT:') === 0) {
             $file = GeneralUtility::getFileAbsFileName($file);
             // as the path is now absolute, make it "relative" to the current script to stay compatible
-            $file = PathUtility::getRelativePathTo($file);
+            $file = PathUtility::getRelativePathTo($file) ?? '';
             $file = rtrim($file, '/');
         } else {
             $file = GeneralUtility::resolveBackPath($file);
@@ -2695,6 +2697,9 @@ class PageRenderer implements SingletonInterface
     protected function createInlineCssTagFromFile(string $file, array $properties): string
     {
         $cssInline = file_get_contents($file);
+        if ($cssInline === false) {
+            return '';
+        }
         $cssInlineFix = $this->getPathFixer()->fixRelativeUrlPaths($cssInline, '/' . PathUtility::dirname($file) . '/');
         return '<style type="text/css"'
             . ' media="' . htmlspecialchars($properties['media']) . '"'
-- 
GitLab