From e6a09e3b5d4afad94bcd63e2700bfb158cf50b3c 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 Charset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: #92276 Change-Id: I28290de708946358794bfa73cac9c7c49ec1cc8b Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65682 Tested-by: TYPO3com <noreply@typo3.com> Tested-by: Oliver Bartsch <bo@cedev.de> Tested-by: Daniel Goerz <daniel.goerz@posteo.de> Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Jörg Bösche <typo3@joergboesche.de> Reviewed-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de> --- .../core/Classes/Charset/CharsetConverter.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/typo3/sysext/core/Classes/Charset/CharsetConverter.php b/typo3/sysext/core/Classes/Charset/CharsetConverter.php index 6966fe752d79..6e3749eb67f0 100644 --- a/typo3/sysext/core/Classes/Charset/CharsetConverter.php +++ b/typo3/sysext/core/Classes/Charset/CharsetConverter.php @@ -429,10 +429,10 @@ class CharsetConverter implements SingletonInterface // Caching brought parsing time for gb2312 down from 2400 ms to 150 ms. For other charsets we are talking 11 ms down to zero. $cacheFile = Environment::getVarPath() . '/charset/charset_' . $charset . '.tbl'; if ($cacheFile && @is_file($cacheFile)) { - $this->parsedCharsets[$charset] = unserialize(file_get_contents($cacheFile), ['allowed_classes' => false]); + $this->parsedCharsets[$charset] = unserialize((string)file_get_contents($cacheFile), ['allowed_classes' => false]); } else { // Parse conversion table into lines: - $lines = GeneralUtility::trimExplode(LF, file_get_contents($charsetConvTableFile), true); + $lines = GeneralUtility::trimExplode(LF, (string)file_get_contents($charsetConvTableFile), true); // Initialize the internal variable holding the conv. table: $this->parsedCharsets[$charset] = ['local' => [], 'utf8' => []]; // traverse the lines: @@ -462,7 +462,7 @@ class CharsetConverter implements SingletonInterface $decval = hexdec(trim($hexbyte)); if ($decval > 127) { $utf8decval = hexdec(substr(trim($utf8), 2)); - $this->parsedCharsets[$charset]['local'][$decval] = $this->UnumberToChar($utf8decval); + $this->parsedCharsets[$charset]['local'][$decval] = $this->UnumberToChar((int)$utf8decval); $this->parsedCharsets[$charset]['utf8'][$this->parsedCharsets[$charset]['local'][$decval]] = $decval; } } @@ -495,7 +495,7 @@ class CharsetConverter implements SingletonInterface } // Use cached version if possible if ($cacheFileASCII && @is_file($cacheFileASCII)) { - $this->toASCII['utf-8'] = unserialize(file_get_contents($cacheFileASCII), ['allowed_classes' => false]); + $this->toASCII['utf-8'] = unserialize((string)file_get_contents($cacheFileASCII), ['allowed_classes' => false]); return 2; } // Process main Unicode data file @@ -516,7 +516,7 @@ class CharsetConverter implements SingletonInterface // Array of chars to be omitted (eg. Russian hard sign) $omit = []; while (!feof($fh)) { - $line = fgets($fh, 4096); + $line = (string)fgets($fh, 4096); // Has a lot of info [$char, $name, $cat, , , $decomp, , , $num] = explode(';', rtrim($line)); $ord = hexdec($char); @@ -619,18 +619,18 @@ class CharsetConverter implements SingletonInterface foreach ($decomposition as $from => $to) { $code_decomp = []; while ($code_value = array_shift($to)) { - $ord = hexdec($code_value); + $ord = (int)hexdec($code_value); if ($ord > 127) { continue 2; } // Skip decompositions containing non-ASCII chars $code_decomp[] = chr($ord); } - $this->toASCII['utf-8'][$this->UnumberToChar(hexdec(substr($from, 2)))] = implode('', $code_decomp); + $this->toASCII['utf-8'][$this->UnumberToChar((int)hexdec(substr($from, 2)))] = implode('', $code_decomp); } // Add numeric decompositions foreach ($number as $from => $to) { - $utf8_char = $this->UnumberToChar(hexdec(substr($from, 2))); + $utf8_char = $this->UnumberToChar((int)hexdec(substr($from, 2))); if (!isset($this->toASCII['utf-8'][$utf8_char])) { $this->toASCII['utf-8'][$utf8_char] = $to; } @@ -657,7 +657,7 @@ class CharsetConverter implements SingletonInterface // Use cached version if possible $cacheFile = Environment::getVarPath() . '/charset/csascii_' . $charset . '.tbl'; if ($cacheFile && @is_file($cacheFile)) { - $this->toASCII[$charset] = unserialize(file_get_contents($cacheFile), ['allowed_classes' => false]); + $this->toASCII[$charset] = unserialize((string)file_get_contents($cacheFile), ['allowed_classes' => false]); return 2; } // Init UTF-8 conversion for this charset -- GitLab