Skip to content

Commit

Permalink
[BUGFIX] Remaining PHP 8.0 fixes for acceptance tests
Browse files Browse the repository at this point in the history
This fixes a bunch of PHP 8.0 warnings found by acceptance
testing. image processing and ext:scheduler are affected
for the main part.
This makes the ac test suite green with PHP 8.0. The
gitlab activation and another testing-framework raise
will follow with dedicated patches.
The patch brings an additional acceptance test for
install tool 'Environment->Image Processing' since
this worked well to nail lots of issues with
GifBuilder and friends.

Change-Id: Id22c7636da76778b75f087d20d7b7260cd2637ee
Resolves: #94333
Related: #94057
Releases: master
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69476
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
lolli42 authored and bmack committed Jun 14, 2021
1 parent 24f9946 commit baae054
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function getGroupsFromShortcuts(): array
$groups = [];

foreach ($this->shortcuts as $shortcut) {
$groups[$shortcut['group']] = $this->shortcutGroups[$shortcut['group']];
$groups[$shortcut['group']] = $this->shortcutGroups[$shortcut['group']] ?? '';
}

return array_unique($groups);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected function findByTable($tableName, $pageIdList, $firstResult, $maxResult
$queryBuilder->andWhere($this->userPermissions);
}

$orderBy = $GLOBALS['TCA'][$tableName]['ctrl']['sortby'] ?? $GLOBALS['TCA'][$tableName]['ctrl']['default_sortby'];
$orderBy = $GLOBALS['TCA'][$tableName]['ctrl']['sortby'] ?? $GLOBALS['TCA'][$tableName]['ctrl']['default_sortby'] ?? '';
foreach (QueryHelper::parseOrderBy((string)$orderBy) as $orderPair) {
[$fieldName, $order] = $orderPair;
$queryBuilder->addOrderBy($fieldName, $order);
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/backend/Classes/Utility/BackendUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ public static function getTCAtypeValue($table, $row)
);
}
$foreignRow = self::getRecord($foreignTable, $foreignUid, $foreignTableTypeField);
if ($foreignRow[$foreignTableTypeField]) {
if ($foreignRow[$foreignTableTypeField] ?? false) {
$typeNum = $foreignRow[$foreignTableTypeField];
}
}
Expand Down Expand Up @@ -2750,7 +2750,7 @@ public static function getModuleData(
$changed = 1;
}
} else {
if ((string)$settings[$key] !== (string)$CHANGED_SETTINGS[$key]) {
if ((string)($settings[$key] ?? '') !== (string)($CHANGED_SETTINGS[$key] ?? '')) {
$settings[$key] = $CHANGED_SETTINGS[$key];
$changed = 1;
}
Expand Down
41 changes: 21 additions & 20 deletions typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,15 +583,15 @@ public function makeText(&$im, $conf, $workArea)
[$spacing, $wordSpacing] = $this->calcWordSpacing($conf);
// Position
$txtPos = $this->txtPosition($conf, $workArea, $conf['BBOX']);
$theText = $conf['text'];
if ($conf['imgMap'] && is_array($conf['imgMap.'])) {
$theText = $conf['text'] ?? '';
if (($conf['imgMap'] ?? false) && is_array($conf['imgMap.'])) {
$this->addToMap($this->calcTextCordsForMap($conf['BBOX'][2], $txtPos, $conf['imgMap.']), $conf['imgMap.']);
}
if (!$conf['hideButCreateMap']) {
if (!($conf['hideButCreateMap'] ?? false)) {
// Font Color:
$cols = $this->convertColor($conf['fontColor']);
// NiceText is calculated
if (!$conf['niceText']) {
if (!($conf['niceText'] ?? false)) {
$Fcolor = imagecolorallocate($im, $cols[0], $cols[1], $cols[2]);
// antiAliasing is setup:
$Fcolor = $conf['antiAlias'] ? $Fcolor : -$Fcolor;
Expand All @@ -600,7 +600,7 @@ public function makeText(&$im, $conf, $workArea)
if ($spacing || $wordSpacing) {
$this->SpacedImageTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, GeneralUtility::getFileAbsFileName($conf['fontFile']), $theText, $spacing, $wordSpacing, $conf['splitRendering.']);
} else {
$this->renderTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'], $conf);
$this->renderTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'] ?? [], $conf);
}
}
} else {
Expand All @@ -613,7 +613,7 @@ public function makeText(&$im, $conf, $workArea)
$fileColor = $tmpStr . '_colorNT.' . $this->gifExtension;
$fileMask = $tmpStr . '_maskNT.' . $this->gifExtension;
// Scalefactor
$sF = MathUtility::forceIntegerInRange($conf['niceText.']['scaleFactor'], 2, 5);
$sF = MathUtility::forceIntegerInRange(($conf['niceText.']['scaleFactor'] ?? 2), 2, 5);
$newW = (int)ceil($sF * imagesx($im));
$newH = (int)ceil($sF * imagesy($im));
// Make mask
Expand All @@ -625,7 +625,7 @@ public function makeText(&$im, $conf, $workArea)
if ($spacing || $wordSpacing) {
$this->SpacedImageTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, GeneralUtility::getFileAbsFileName($conf['fontFile']), $theText, $spacing, $wordSpacing, $conf['splitRendering.'], $sF);
} else {
$this->renderTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'], $conf, $sF);
$this->renderTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'] ?? [], $conf, $sF);
}
$this->ImageWrite($maskImg, $fileMask);
imagedestroy($maskImg);
Expand Down Expand Up @@ -687,7 +687,8 @@ public function txtPosition($conf, $workArea, $BB)
$result[2] = $BB[0];
$result[3] = $BB[1];
$w = $workArea[2];
switch ($conf['align']) {
$alignment = $conf['align'] ?? '';
switch ($alignment) {
case 'right':

case 'center':
Expand All @@ -703,7 +704,7 @@ public function txtPosition($conf, $workArea, $BB)
$result[1] = ceil($len2 * $factor + (1 - $factor) * $len1);
break;
}
switch ($conf['align']) {
switch ($alignment) {
case 'right':
break;
case 'center':
Expand Down Expand Up @@ -733,7 +734,7 @@ public function calcBBox($conf)
$sF = $this->getTextScalFactor($conf);
[$spacing, $wordSpacing] = $this->calcWordSpacing($conf, $sF);
$theText = $conf['text'];
$charInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $theText, $conf['splitRendering.'], $sF);
$charInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $theText, ($conf['splitRendering.'] ?? []), $sF);
$theBBoxInfo = $charInf;
if ($conf['angle']) {
$xArr = [$charInf[0], $charInf[2], $charInf[4], $charInf[6]];
Expand Down Expand Up @@ -993,7 +994,7 @@ public function ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fon
// Initialize:
$colorIndex = $color;
// Set custom color if any (only when niceText is off):
if ($strCfg['color'] && $sF == 1) {
if (($strCfg['color'] ?? false) && $sF == 1) {
$cols = $this->convertColor($strCfg['color']);
$colorIndex = imagecolorallocate($im, $cols[0], $cols[1], $cols[2]);
$colorIndex = $color >= 0 ? $colorIndex : -$colorIndex;
Expand All @@ -1009,8 +1010,8 @@ public function ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fon
imagettftext($im, $this->compensateFontSizeiBasedOnFreetypeDpi($sF * $strCfg['fontSize']), $angle, $x, $y, $colorIndex, $fontFile, $strCfg['str']);
// Calculate offset to apply:
$wordInf = imagettfbbox($this->compensateFontSizeiBasedOnFreetypeDpi($sF * $strCfg['fontSize']), $angle, GeneralUtility::getFileAbsFileName($strCfg['fontFile']), $strCfg['str']);
$x += $wordInf[2] - $wordInf[0] + (int)$splitRendering['compX'] + (int)$strCfg['xSpaceAfter'];
$y += $wordInf[5] - $wordInf[7] - (int)$splitRendering['compY'] - (int)$strCfg['ySpaceAfter'];
$x += $wordInf[2] - $wordInf[0] + (int)($splitRendering['compX'] ?? 0) + (int)($strCfg['xSpaceAfter'] ?? 0);
$y += $wordInf[5] - $wordInf[7] - (int)($splitRendering['compY'] ?? 0) - (int)($strCfg['ySpaceAfter'] ?? 0);
} else {
debug('cannot read file: ' . $fontFile, self::class . '::ImageTTFTextWrapper()');
}
Expand Down Expand Up @@ -1166,8 +1167,8 @@ public function splitString($string, $splitRendering, $fontSize, $fontFile)
*/
public function calcWordSpacing($conf, $scaleFactor = 1)
{
$spacing = (int)$conf['spacing'];
$wordSpacing = (int)$conf['wordSpacing'];
$spacing = (int)($conf['spacing'] ?? 0);
$wordSpacing = (int)($conf['wordSpacing'] ?? 0);
$wordSpacing = $wordSpacing ?: $spacing * 2;
$spacing *= $scaleFactor;
$wordSpacing *= $scaleFactor;
Expand All @@ -1183,11 +1184,11 @@ public function calcWordSpacing($conf, $scaleFactor = 1)
*/
public function getTextScalFactor($conf)
{
if (!$conf['niceText']) {
if (!($conf['niceText'] ?? false)) {
$sF = 1;
} else {
// NICETEXT::
$sF = MathUtility::forceIntegerInRange($conf['niceText.']['scaleFactor'], 2, 5);
$sF = MathUtility::forceIntegerInRange(($conf['niceText.']['scaleFactor'] ?? 2), 2, 5);
}
return $sF;
}
Expand Down Expand Up @@ -1996,7 +1997,7 @@ public function convertColor($string)
}
}
// ... and possibly recalculating the value
if (trim($cParts[1])) {
if (trim($cParts[1] ?? '')) {
$cParts[1] = trim($cParts[1]);
if ($cParts[1][0] === '*') {
$val = (float)substr($cParts[1], 1);
Expand Down Expand Up @@ -2033,7 +2034,7 @@ public function objPosition($conf, $workArea, $BB)
$result[3] = $BB[1];
$w = $workArea[2];
$h = $workArea[3];
$align = explode(',', $conf['align']);
$align = explode(',', $conf['align'] ?? ',');
$align[0] = strtolower(substr(trim($align[0]), 0, 1));
$align[1] = strtolower(substr(trim($align[1]), 0, 1));
switch ($align[0]) {
Expand Down Expand Up @@ -2138,7 +2139,7 @@ public function imageMagickConvert($imagefile, $newExt = '', $w = '', $h = '', $
$info[1] = $data[1];
$frame = $this->addFrameSelection ? (int)$frame : 0;
if (!$params) {
$params = $this->cmds[$newExt];
$params = $this->cmds[$newExt] ?? '';
}
// Cropscaling:
if ($data['crs']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function processWithLocalFile(TaskInterface $task, string $originalFileNa
$gifBuilder = GeneralUtility::makeInstance(GifBuilder::class);

$configuration = $targetFile->getProcessingConfiguration();
$configuration['additionalParameters'] = $this->modifyImageMagickStripProfileParameters($configuration['additionalParameters'], $configuration);
$configuration['additionalParameters'] = $this->modifyImageMagickStripProfileParameters((string)($configuration['additionalParameters'] ?? ''), $configuration);

if (empty($configuration['fileExtension'])) {
$configuration['fileExtension'] = $task->getTargetFileExtension();
Expand Down Expand Up @@ -113,21 +113,21 @@ public function processWithLocalFile(TaskInterface $task, string $originalFileNa
}

// Normal situation (no masking)
if (!(is_array($configuration['maskImages']) && $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_enabled'])) {
if (!(is_array($configuration['maskImages'] ?? null) && $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_enabled'])) {
// the result info is an array with 0=width,1=height,2=extension,3=filename
$result = $gifBuilder->imageMagickConvert(
$originalFileName,
$configuration['fileExtension'],
$configuration['width'],
$configuration['height'],
$configuration['width'] ?? '',
$configuration['height'] ?? '',
$configuration['additionalParameters'],
$configuration['frame'],
$configuration['frame'] ?? '',
$options
);
} else {
$targetFileName = $this->getFilenameForImageCropScaleMask($task);
$temporaryFileName = Environment::getPublicPath() . '/typo3temp/' . $targetFileName;
$maskImage = $configuration['maskImages']['maskImage'];
$maskImage = $configuration['maskImages']['maskImage'] ?? null;
$maskBackgroundImage = $configuration['maskImages']['backgroundImage'];
if ($maskImage instanceof FileInterface && $maskBackgroundImage instanceof FileInterface) {
$temporaryExtension = 'png';
Expand All @@ -138,10 +138,10 @@ public function processWithLocalFile(TaskInterface $task, string $originalFileNa
$tempFileInfo = $gifBuilder->imageMagickConvert(
$originalFileName,
$temporaryExtension,
$configuration['width'],
$configuration['height'],
$configuration['width'] ?? '',
$configuration['height'] ?? '',
$configuration['additionalParameters'],
$configuration['frame'],
$configuration['frame'] ?? '',
$options
);
if (is_array($tempFileInfo)) {
Expand Down Expand Up @@ -219,24 +219,24 @@ protected function getConfigurationForImageCropScaleMask(ProcessedFile $processe
{
$configuration = $processedFile->getProcessingConfiguration();

if ($configuration['useSample']) {
if ($configuration['useSample'] ?? false) {
$gifBuilder->scalecmd = '-sample';
}
$options = [];
if ($configuration['maxWidth']) {
if ($configuration['maxWidth'] ?? false) {
$options['maxW'] = $configuration['maxWidth'];
}
if ($configuration['maxHeight']) {
if ($configuration['maxHeight'] ?? false) {
$options['maxH'] = $configuration['maxHeight'];
}
if ($configuration['minWidth']) {
if ($configuration['minWidth'] ?? false) {
$options['minW'] = $configuration['minWidth'];
}
if ($configuration['minHeight']) {
if ($configuration['minHeight'] ?? false) {
$options['minH'] = $configuration['minHeight'];
}

$options['noScale'] = $configuration['noScale'];
$options['noScale'] = $configuration['noScale'] ?? null;

return $options;
}
Expand Down Expand Up @@ -268,7 +268,7 @@ protected function getFilenameForImageCropScaleMask(TaskInterface $task)
* @param array $configuration The TypoScript configuration of [IMAGE].file
* @return string
*/
protected function modifyImageMagickStripProfileParameters($parameters, array $configuration)
protected function modifyImageMagickStripProfileParameters(string $parameters, array $configuration)
{
// Strips profile information of image to save some space:
if (isset($configuration['stripProfile'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@

namespace TYPO3\CMS\Core\Resource\Processing;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Imaging\GraphicalFunctions;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Processes Local Images files
*/
class LocalImageProcessor implements ProcessorInterface
class LocalImageProcessor implements ProcessorInterface, LoggerAwareInterface
{
use LoggerAwareTrait;

/**
* Returns TRUE if this processor can process the given task.
*
Expand Down Expand Up @@ -72,15 +76,22 @@ public function processTaskWithLocalFile(TaskInterface $task, ?string $localFile
$task->setExecuted(true);
$imageDimensions = $this->getGraphicalFunctionsObject()->getImageDimensions($result['filePath']);
$task->getTargetFile()->setName($task->getTargetFileName());
$task->getTargetFile()->updateProperties(
['width' => $imageDimensions[0], 'height' => $imageDimensions[1], 'size' => filesize($result['filePath']), 'checksum' => $task->getConfigurationChecksum()]
);
$task->getTargetFile()->updateProperties([
'width' => $imageDimensions[0] ?? 0,
'height' => $imageDimensions[1] ?? 0,
'size' => filesize($result['filePath']),
'checksum' => $task->getConfigurationChecksum()
]);
$task->getTargetFile()->updateWithLocalFile($result['filePath']);
} else {
// Seems we have no valid processing result
$task->setExecuted(false);
}
} catch (\Exception $e) {
// @todo: Swallowing all exceptions including PHP warnings here is a bad idea.
// @todo: This should be restricted to more specific exceptions - if at all.
// @todo: For now, we at least log the situation.
$this->logger->error(sprintf('Processing task of image file'), ['exception' => $e]);
$task->setExecuted(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ public static function checkIncludeLines($string, $cycle_counter = 1, $returnFil
// load default TypoScript
$defaultTypoScriptKey = implode('/', $filePointerPathParts) . '/';
if (in_array($defaultTypoScriptKey, $GLOBALS['TYPO3_CONF_VARS']['FE']['contentRenderingTemplates'], true)) {
$newString .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $includeType . '.']['defaultContentRendering'];
$newString .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $includeType . '.']['defaultContentRendering'] ?? '';
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/core/Classes/Utility/GeneralUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -1388,13 +1388,13 @@ public static function array2xml(array $array, $NSprefix = '', $level = 0, $docT
$tagName = (string)$options['parentTagMap'][$stackData['parentTagName']];
} elseif (MathUtility::canBeInterpretedAsInteger($tagName)) {
// If integer...;
if ($options['useNindex']) {
if ($options['useNindex'] ?? false) {
// If numeric key, prefix "n"
$tagName = 'n' . $tagName;
} else {
// Use special tag for num. keys:
$attr .= ' index="' . $tagName . '"';
$tagName = $options['useIndexTagForNum'] ?: 'numIndex';
$tagName = ($options['useIndexTagForNum'] ?? false) ?: 'numIndex';
}
} elseif (!empty($options['useIndexTagForAssoc'])) {
// Use tag for all associative keys:
Expand Down

0 comments on commit baae054

Please sign in to comment.