From 509b6a021dd026588fa44edf80f96cec4e13951e 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 Service

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: #92259
Change-Id: I55ca9df860afeb95571e6372a006799c29817576
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65675
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Benni Mack <benni@typo3.org>
---
 .../core/Classes/Service/AbstractService.php       | 14 +++++++++-----
 .../core/Classes/Service/Archive/ZipService.php    |  2 +-
 .../core/Classes/Service/OpcodeCacheService.php    |  2 +-
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/typo3/sysext/core/Classes/Service/AbstractService.php b/typo3/sysext/core/Classes/Service/AbstractService.php
index 0f89c57c668e..b682de93702a 100644
--- a/typo3/sysext/core/Classes/Service/AbstractService.php
+++ b/typo3/sysext/core/Classes/Service/AbstractService.php
@@ -329,7 +329,7 @@ abstract class AbstractService implements LoggerAwareInterface
      *
      * @param string $absFile File name to read from.
      * @param int $length Maximum length to read. If empty the whole file will be read.
-     * @return string|bool $content or FALSE
+     * @return string|bool file content or false
      */
     public function readFile($absFile, $length = 0)
     {
@@ -354,8 +354,12 @@ abstract class AbstractService implements LoggerAwareInterface
     {
         if (!$absFile) {
             $absFile = $this->tempFile($this->prefixId);
+            if ($absFile === false) {
+                return false;
+            }
+            $absFile = (string)$absFile;
         }
-        if ($absFile && GeneralUtility::isAllowedAbsPath($absFile)) {
+        if (GeneralUtility::isAllowedAbsPath($absFile)) {
             if ($fd = @fopen($absFile, 'wb')) {
                 @fwrite($fd, $content);
                 @fclose($fd);
@@ -446,7 +450,7 @@ abstract class AbstractService implements LoggerAwareInterface
      * Get the input content.
      * Will be read from input file if needed. (That is if ->inputContent is empty and ->inputFile is not)
      *
-     * @return mixed
+     * @return string|bool
      */
     public function getInput()
     {
@@ -481,7 +485,7 @@ abstract class AbstractService implements LoggerAwareInterface
     /**
      * Set the output file name.
      *
-     * @param string $absFile File name
+     * @param string|bool $absFile File name
      */
     public function setOutputFile($absFile)
     {
@@ -491,7 +495,7 @@ abstract class AbstractService implements LoggerAwareInterface
     /**
      * Get the output content.
      *
-     * @return mixed
+     * @return string
      */
     public function getOutput()
     {
diff --git a/typo3/sysext/core/Classes/Service/Archive/ZipService.php b/typo3/sysext/core/Classes/Service/Archive/ZipService.php
index 02e1e834b098..0681a6aacbf6 100644
--- a/typo3/sysext/core/Classes/Service/Archive/ZipService.php
+++ b/typo3/sysext/core/Classes/Service/Archive/ZipService.php
@@ -73,7 +73,7 @@ class ZipService
         }
 
         for ($i = 0; $i < $zip->numFiles; $i++) {
-            $entryName = $zip->getNameIndex($i);
+            $entryName = (string)$zip->getNameIndex($i);
             if (preg_match('#/(?:\.{2,})+#', $entryName) // Contains any traversal sequence starting with a slash, e.g. /../, /.., /.../
                 || preg_match('#^(?:\.{2,})+/#', $entryName) // Starts with a traversal sequence, e.g. ../, .../
             ) {
diff --git a/typo3/sysext/core/Classes/Service/OpcodeCacheService.php b/typo3/sysext/core/Classes/Service/OpcodeCacheService.php
index 399967fda9f0..2e9eb76cfb0c 100644
--- a/typo3/sysext/core/Classes/Service/OpcodeCacheService.php
+++ b/typo3/sysext/core/Classes/Service/OpcodeCacheService.php
@@ -74,7 +74,7 @@ class OpcodeCacheService
      */
     protected static function isClearable(): bool
     {
-        $disabled = explode(',', ini_get('disable_functions'));
+        $disabled = explode(',', (string)ini_get('disable_functions'));
         return !(in_array('opcache_invalidate', $disabled, true) || in_array('opcache_reset', $disabled, true));
     }
 }
-- 
GitLab