Commit e6597404 authored by Daniel Goerz's avatar Daniel Goerz Committed by Anja Leichsenring
Browse files

[TASK] Run phpstan with PHP 8 in nightly and premerge builds

Resolves: #93704
Releases: master
Change-Id: I24067c4b705c671b87a9bbdfed30535a39528879
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/68359


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
parent 30bf9dcc
......@@ -96,3 +96,15 @@ phpstan php 7.4:
script:
- Build/Scripts/runTests.sh -s composerInstall -p 7.4
- Build/Scripts/runTests.sh -s phpstan -p 7.4
phpstan php 8.0:
stage: integrity
only:
- schedules
cache:
key: master-composer-phpstan-80
paths:
- .cache
script:
- Build/Scripts/runTests.sh -s composerInstall -p 8.0
- Build/Scripts/runTests.sh -s phpstan -p 8.0
......@@ -98,3 +98,17 @@ phpstan php 7.4 pre-merge:
- Build/Scripts/runTests.sh -s composerInstall -p 7.4
- Build/Scripts/runTests.sh -s phpstan -p 7.4
phpstan php 8.0 pre-merge:
stage: main
except:
refs:
- schedules
- master
cache:
key: master-composer-phpstan-80
paths:
- .cache
script:
- Build/Scripts/runTests.sh -s composerInstall -p 8.0
- Build/Scripts/runTests.sh -s phpstan -p 8.0
<?php
declare(strict_types=1);
$config = [];
if (PHP_MAJOR_VERSION === 7) {
$config['parameters']['ignoreErrors'] = [
'#Class GdImage not found.#',
[
'message' => '#^Parameter \\#[1-4]{1} \\$[a-z]* of function [a-z_]* expects resource, resource\\|XmlParser given\\.$#',
'path' => '../typo3/sysext/extensionmanager/Classes/Utility/Parser/ExtensionXmlPushParser.php',
'count' => 9,
],
[
'message' => '#^Parameter \\#1 \\$sem_identifier of function sem_release expects resource, resource\\|SysvSemaphore given\\.$#',
'path' => '../typo3/sysext/core/Classes/Locking/SemaphoreLockStrategy.php',
'count' => 1,
],
[
'message' => '#^Parameter \\#1 \\$sem_identifier of function sem_remove expects resource, resource\\|SysvSemaphore given\\.$#',
'path' => '../typo3/sysext/core/Classes/Locking/SemaphoreLockStrategy.php',
'count' => 1,
]
];
}
return $config;
<?php
declare(strict_types=1);
$config = [];
if (PHP_MAJOR_VERSION === 8) {
$config['parameters']['ignoreErrors'] = [
[
'message' => '#^Parameter \\#1 \\$image of function imagedestroy expects GdImage, GdImage\\|false given\\.$#',
'path' => '../typo3/sysext/install/Classes/SystemEnvironment/Check.php',
'count' => 3,
],
[
'message' => '#^Parameter \\#6 \\$color of function imagefilledrectangle expects int, int\\|false given\\.$#',
'path' => '../typo3/sysext/install/Classes/Controller/EnvironmentController.php',
'count' => 4,
],
[
'message' => '#^Parameter \\#1 \\$image of function imagefilledrectangle expects GdImage, GdImage\\|false given\\.$#',
'path' => '../',
'count' => 4,
],
[
'message' => '#^Parameter \\#1 \\$image of function imagegif expects GdImage, GdImage\\|false given\\.$#',
'path' => '../',
'count' => 1,
],
[
'message' => '#^Parameter \\#6 \\$color of function imagettftext expects int, int\\|false given\\.$#',
'path' => '../',
'count' => 1,
],
[
'message' => '#^Parameter \\#1 \\$image of function imagettftext expects GdImage, GdImage\\|false given\\.$#',
'path' => '../',
'count' => 1,
],
[
'message' => '#^Parameter \\#1 \\$image of function imagecolorallocate expects GdImage, GdImage\\|false given\\.$#',
'path' => '../',
'count' => 6,
],
[
'message' => '#^Parameter \\#2 \\$color of function imagecolortransparent expects int\\|null, int\\|false given\\.$#',
'path' => '../typo3/sysext/frontend/Classes/Imaging/GifBuilder.php',
'count' => 1,
],
[
'message' => '#^Parameter \\#6 \\$color of function imagefilledrectangle expects int, int\\|false given\\.$#',
'path' => '../typo3/sysext/frontend/Classes/Imaging/GifBuilder.php',
'count' => 1,
],
[
'message' => '#^Parameter \\#4 \\$color of function imagefill expects int, int\\|false given\\.$#',
'path' => '../typo3/sysext/frontend/Classes/Imaging/GifBuilder.php',
'count' => 1,
],
[
'message' => '#^Parameter \\#[1-4]{1} \\$[a-z]* of function [a-z_]* expects XmlParser, resource\\|XmlParser given\\.$#',
'path' => '../typo3/sysext/extensionmanager/Classes/Utility/Parser/ExtensionXmlPushParser.php',
'count' => 9,
],
[
'message' => '#^Parameter \\#1 \\$semaphore of function sem_release expects SysvSemaphore, resource\\|SysvSemaphore given\\.$#',
'path' => '../typo3/sysext/core/Classes/Locking/SemaphoreLockStrategy.php',
'count' => 1,
],
[
'message' => '#^Parameter \\#1 \\$semaphore of function sem_remove expects SysvSemaphore, resource\\|SysvSemaphore given\\.$#',
'path' => '../typo3/sysext/core/Classes/Locking/SemaphoreLockStrategy.php',
'count' => 1,
],
[
'message' => '#^Parameter \\#1 \\$function of class ReflectionFunction constructor expects Closure\\|string, callable\\(\\)\\: mixed given\\.$#',
'path' => '../typo3/sysext/core/Classes/DependencyInjection/ServiceProviderCompilationPass.php',
'count' => 1,
],
[
'message' => '#^Parameter \\#1 \\$value of function count expects array\\|Countable, string given\\.$#',
'path' => '../typo3/sysext/core/Classes/Database/QueryGenerator.php',
'count' => 2,
],
[
'message' => '#^Parameter \\#1 \\$array of function array_slice expects array, string given\\.$#',
'path' => '../typo3/sysext/core/Classes/Database/QueryGenerator.php',
'count' => 2,
],
[
'message' => '#^Parameter \\#1 \\$callback of function set_exception_handler expects \\(callable\\(Throwable\\)\\: void\\)\\|null, array\\(\\$this\\(TYPO3\\\\CMS\\\\Core\\\\Error\\\\DebugExceptionHandler\\), \'handleException\'\\) given\\.$#',
'path' => '../typo3/sysext/core/Classes/Error/DebugExceptionHandler.php',
'count' => 1,
],
[
'message' => '#^Parameter \\#1 \\$callback of function set_exception_handler expects \\(callable\\(Throwable\\)\\: void\\)\\|null, array\\(\\$this\\(TYPO3\\\\CMS\\\\Core\\\\Error\\\\ProductionExceptionHandler\\), \'handleException\'\\) given\\.$#',
'path' => '../typo3/sysext/core/Classes/Error/ProductionExceptionHandler.php',
'count' => 1,
],
];
}
return $config;
includes:
- vendor/friendsoftypo3/phpstan-typo3/extension.neon
- Build/phpstan.level8.neon
- Build/phpstan.php7config.php
- Build/phpstan.php8config.php
# Include bleeding edge rules if necessary but do not commit
# - vendor/phpstan/phpstan/conf/bleedingEdge.neon
......@@ -33,10 +35,9 @@ parameters:
- %currentWorkingDirectory%/typo3/sysext/*/Documentation/*
- %currentWorkingDirectory%/typo3/sysext/*/Resources/*
- %currentWorkingDirectory%/typo3/sysext/*/Configuration/*
- %currentWorkingDirectory%/typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
ignoreErrors:
# PHP8 compatibility, as phpstan cannot detect this yet.
- "#Class GdImage not found.#"
- "#^Parameter \\#1 \\$disable of function libxml_disable_entity_loader expects bool, bool\\|null given\\.$#"
# ignored errors for level 0
......@@ -179,86 +180,6 @@ parameters:
message: "#^Parameter \\#1 \\$constraint of static method TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\QueryHelper\\:\\:stripLogicalOperatorPrefix\\(\\) expects string, string\\|null given\\.$#"
count: 1
path: typo3/sysext/core/Classes/Database/QueryView.php
-
message: "#^Parameter \\#1 \\$im of function imagesavealpha expects resource, resource\\|false given\\.$#"
count: 3
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#1 \\$im of function imagecolorallocatealpha expects resource, resource\\|false given\\.$#"
count: 2
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#1 \\$im of function imagefill expects resource, resource\\|false given\\.$#"
count: 2
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#4 \\$col of function imagefill expects int, int\\|false given\\.$#"
count: 2
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#1 \\$im of function imagecolorallocate expects resource, resource\\|false given\\.$#"
count: 11
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#1 \\$im of function imagefilledrectangle expects resource, resource\\|false given\\.$#"
count: 11
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#6 \\$col of function imagefilledrectangle expects int, int\\|false given\\.$#"
count: 12
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#1 \\$dst_im of function imagecopyresized expects resource, resource\\|false given\\.$#"
count: 2
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#6 \\$Fcolor of method TYPO3\\\\CMS\\\\Core\\\\Imaging\\\\GraphicalFunctions\\:\\:SpacedImageTTFText\\(\\) expects int, int\\|false given\\.$#"
count: 2
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#6 \\$color of method TYPO3\\\\CMS\\\\Core\\\\Imaging\\\\GraphicalFunctions\\:\\:renderTTFText\\(\\) expects int, int\\|false given\\.$#"
count: 2
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#1 \\$destImg of method TYPO3\\\\CMS\\\\Core\\\\Imaging\\\\GraphicalFunctions\\:\\:ImageWrite\\(\\) expects resource, resource\\|false given\\.$#"
count: 2
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#1 \\$im of function imagedestroy expects resource, resource\\|false given\\.$#"
count: 3
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#6 \\$col of function imagettftext expects int, int\\|false given\\.$#"
count: 1
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#6 \\$color of function imagefilledellipse expects int, int\\|false given\\.$#"
count: 1
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#4 \\$green of function imagecolorset expects int, float given\\.$#"
count: 2
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#5 \\$blue of function imagecolorset expects int, float given\\.$#"
count: 2
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#1 \\$im of function imagegif expects resource, resource\\|false given\\.$#"
count: 2
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#1 \\$im of function imagestring expects resource, resource\\|false given\\.$#"
count: 3
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#6 \\$col of function imagestring expects int, int\\|false given\\.$#"
count: 3
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#1 \\$im of function imagepng expects resource, resource\\|false given\\.$#"
count: 1
path: typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
-
message: "#^Parameter \\#2 \\$id of method TYPO3\\\\CMS\\\\Core\\\\DataHandling\\\\DataHandler\\:\\:getRecordProperties\\(\\) expects int, int\\|string given\\.$#"
count: 2
......@@ -336,15 +257,15 @@ parameters:
count: 1
path: typo3/sysext/frontend/Classes/ContentObject/ScalableVectorGraphicsContentObject.php
-
message: "#^Parameter \\#1 \\$array_arg of function current expects array, object given\\.$#"
message: "#^Parameter \\#1 \\$(array_arg|array) of function current expects array, object given\\.$#"
count: 1
path: typo3/sysext/extbase/Classes/Persistence/Generic/LazyLoadingProxy.php
-
message: "#^Parameter \\#1 \\$array_arg of function key expects array, object given\\.$#"
message: "#^Parameter \\#1 \\$(array_arg|array) of function key expects array, object given\\.$#"
count: 1
path: typo3/sysext/extbase/Classes/Persistence/Generic/LazyLoadingProxy.php
-
message: "#^Parameter \\#1 \\$array_arg of function next expects array, object given\\.$#"
message: "#^Parameter \\#1 \\$(array_arg|array) of function next expects array, object given\\.$#"
count: 1
path: typo3/sysext/extbase/Classes/Persistence/Generic/LazyLoadingProxy.php
-
......
......@@ -6166,7 +6166,10 @@ class DataHandler implements LoggerAwareInterface
}
// Process the arguments with the defined function:
if (!empty($remapAction['func'])) {
$newValue = call_user_func_array([$this, $remapAction['func']], $remapAction['args']);
$callable = [$this, $remapAction['func']];
if (is_callable($callable)) {
$newValue = call_user_func_array($callable, $remapAction['args']);
}
}
// If array is returned, check for maxitems condition, if string is returned this was already done:
if (is_array($newValue)) {
......
......@@ -1294,7 +1294,7 @@ class QueryGenerator
return false;
}
$format = 'Y-m-d\\TH:i:s\\Z';
$formattedDate = \DateTime::createFromFormat($format, $date);
$formattedDate = \DateTime::createFromFormat($format, (string)$date);
return $formattedDate && $formattedDate->format($format) === $date;
}
......@@ -1345,7 +1345,7 @@ class QueryGenerator
$inputVal = $this->cleanInputVal($conf, '1');
$qsTmp = str_replace('#VALUE1#', trim($queryBuilder->quote($inputVal), '\''), $qsTmp);
}
$qs .= trim($qsTmp);
$qs .= trim((string)$qsTmp);
return $qs;
}
......@@ -1698,7 +1698,7 @@ class QueryGenerator
*/
protected function getDateTimePickerField($name, $timestamp, $type)
{
$value = strtotime($timestamp) ? date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], strtotime($timestamp)) : '';
$value = strtotime($timestamp) ? date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], (int)strtotime($timestamp)) : '';
$id = StringUtility::getUniqueId('dt_');
$html = [];
$html[] = '<div class="input-group" id="' . $id . '-wrapper">';
......
......@@ -843,15 +843,15 @@ class QueryView
switch ($fields['type']) {
case 'date':
if ($fieldValue != -1) {
$out = strftime('%d-%m-%Y', $fieldValue);
$out = strftime('%d-%m-%Y', (int)$fieldValue);
}
break;
case 'time':
if ($fieldValue != -1) {
if ($splitString === '<br />') {
$out = strftime('%H:%M' . $splitString . '%d-%m-%Y', $fieldValue);
$out = strftime('%H:%M' . $splitString . '%d-%m-%Y', (int)$fieldValue);
} else {
$out = strftime('%H:%M %d-%m-%Y', $fieldValue);
$out = strftime('%H:%M %d-%m-%Y', (int)$fieldValue);
}
}
break;
......
......@@ -31,7 +31,10 @@ class DebugExceptionHandler extends AbstractExceptionHandler
*/
public function __construct()
{
set_exception_handler([$this, 'handleException']);
$callable = [$this, 'handleException'];
if (is_callable($callable)) {
set_exception_handler($callable);
}
}
/**
......
......@@ -47,7 +47,10 @@ class ProductionExceptionHandler extends AbstractExceptionHandler
*/
public function __construct()
{
set_exception_handler([$this, 'handleException']);
$callable = [$this, 'handleException'];
if (is_callable($callable)) {
set_exception_handler($callable);
}
}
/**
......
......@@ -93,6 +93,9 @@ class Stream implements StreamInterface
return;
}
$resource = $this->detach();
if ($resource === null) {
return;
}
fclose($resource);
}
......
......@@ -37,7 +37,7 @@ class SemaphoreLockStrategy implements LockingStrategyInterface
protected $id;
/**
* @var resource Semaphore Resource used for this lock
* @var resource|\SysvSemaphore Semaphore Resource used for this lock
*/
protected $resource;
......
......@@ -1746,7 +1746,7 @@ class GeneralUtility
$targetPermissions = str_pad($targetPermissions, 4, '0', STR_PAD_LEFT);
$targetPermissions = octdec($targetPermissions);
// "@" is there because file is not necessarily OWNED by the user
$result = @chmod($path, $targetPermissions);
$result = @chmod($path, (int)$targetPermissions);
}
// Set createGroup if not empty
if (
......@@ -1870,7 +1870,7 @@ class GeneralUtility
*/
public static function mkdir($newFolder)
{
$result = @mkdir($newFolder, octdec($GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask']));
$result = @mkdir($newFolder, (int)octdec($GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask']));
if ($result) {
static::fixPermissions($newFolder);
}
......@@ -1915,7 +1915,7 @@ class GeneralUtility
{
$currentPath = $fullDirectoryPath;
$firstCreatedPath = '';
$permissionMask = octdec($GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask']);
$permissionMask = (int)octdec($GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask']);
if (!@is_dir($currentPath)) {
do {
$firstCreatedPath = $currentPath;
......
......@@ -63,7 +63,7 @@ class ExtensionXmlPushParser extends AbstractExtensionXmlParser
public function parseXml($file)
{
$this->createParser();
if (!is_resource($this->objXml)) {
if (!is_resource($this->objXml) && !$this->objXml instanceof \XmlParser) {
throw new ExtensionManagerException('Unable to create XML parser.', 1342640663);
}
// Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
......@@ -72,8 +72,8 @@ class ExtensionXmlPushParser extends AbstractExtensionXmlParser
$previousValueOfEntityLoader = libxml_disable_entity_loader(true);
}
// keep original character case of XML document
xml_parser_set_option($this->objXml, XML_OPTION_CASE_FOLDING, false);
xml_parser_set_option($this->objXml, XML_OPTION_SKIP_WHITE, false);
xml_parser_set_option($this->objXml, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($this->objXml, XML_OPTION_SKIP_WHITE, 0);
xml_parser_set_option($this->objXml, XML_OPTION_TARGET_ENCODING, 'utf-8');
xml_set_element_handler($this->objXml, [$this, 'startElement'], [$this, 'endElement']);
xml_set_character_data_handler($this->objXml, [$this, 'characterData']);
......
......@@ -149,7 +149,7 @@ abstract class AbstractNode
1366744035
);
}
$result = @chmod($this->getAbsolutePath(), octdec($this->getTargetPermission()));
$result = @chmod($this->getAbsolutePath(), (int)octdec($this->getTargetPermission()));
if ($result === true) {
return new FlashMessage(
'',
......
......@@ -354,7 +354,7 @@ class NormalizeCommand
}
if (!$normalizedWeekday) {
// Convert string representation like 'sun' to integer
$timestamp = strtotime('next ' . $weekday, mktime(0, 0, 0, 1, 1, 2010));
$timestamp = strtotime('next ' . $weekday, (int)mktime(0, 0, 0, 1, 1, 2010));
if (!$timestamp || $timestamp < strtotime('2010-01-01') || $timestamp > strtotime('2010-01-08')) {
throw new \InvalidArgumentException('Unable to convert given weekday name.', 1291163589);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment