Commit f9c1ed54 authored by Simon Schaufelberger's avatar Simon Schaufelberger Committed by Stefan Bürk
Browse files

[TASK] Solve several phpstan issues in GifBuilder

Also add some (indirect) basic tests for
GifBuilder::calculateValue.

Used command:

> Build/Scripts/runTests.sh -s phpstanGenerateBaseline

Resolves: #97690
Releases: main, 11.5
Change-Id: I836db8570f64ecb2729c1707fcfe9fc1af672151
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74743


Tested-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
parent 520ecd36
Pipeline #27758 passed with stages
in 18 minutes and 10 seconds
......@@ -3620,16 +3620,6 @@ parameters:
count: 1
path: ../../typo3/sysext/frontend/Classes/Http/RequestHandler.php
-
message: "#^Method TYPO3\\\\CMS\\\\Frontend\\\\Imaging\\\\GifBuilder\\:\\:calculateValue\\(\\) should return int but returns float\\.$#"
count: 1
path: ../../typo3/sysext/frontend/Classes/Imaging/GifBuilder.php
-
message: "#^Method TYPO3\\\\CMS\\\\Frontend\\\\Imaging\\\\GifBuilder\\:\\:checkTextObj\\(\\) should return array but returns null\\.$#"
count: 1
path: ../../typo3/sysext/frontend/Classes/Imaging/GifBuilder.php
-
message: "#^Property TYPO3\\\\CMS\\\\Core\\\\Imaging\\\\GraphicalFunctions\\:\\:\\$setup \\(array\\) on left side of \\?\\? is not nullable\\.$#"
count: 9
......
......@@ -539,7 +539,7 @@ class GifBuilder extends GraphicalFunctions
* Performs caseshift if any.
*
* @param array $conf GIFBUILDER object TypoScript properties
* @return array Modified $conf array IF the "text" property is not blank
* @return array|null Modified $conf array IF the "text" property is not blank
* @internal
*/
public function checkTextObj($conf)
......@@ -792,14 +792,14 @@ class GifBuilder extends GraphicalFunctions
} elseif ($sign === '+') {
$calculatedValue += $theVal;
} elseif ($sign === '/' && $theVal) {
$calculatedValue = $calculatedValue / $theVal;
$calculatedValue /= $theVal;
} elseif ($sign === '*') {
$calculatedValue = $calculatedValue * $theVal;
$calculatedValue *= $theVal;
} elseif ($sign === '%' && $theVal) {
$calculatedValue %= $theVal;
}
}
return round($calculatedValue);
return (int)round($calculatedValue);
}
/**
......
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Frontend\Tests\Unit\Imaging;
use TYPO3\CMS\Frontend\Imaging\GifBuilder;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/**
* @covers \TYPO3\CMS\Frontend\Imaging\GifBuilder
*/
class GifBuilderTest extends UnitTestCase
{
protected bool $resetSingletonInstances = true;
private GifBuilder $subject;
protected function setUp(): void
{
parent::setUp();
$this->subject = new GifBuilder();
}
/**
* @return array<string, array{0: non-empty-string}>
*/
public function singleIntegerDataProvider(): array
{
return [
'positive integer' => ['1'],
'negative integer' => ['-1'],
'zero' => ['0'],
];
}
/**
* @test
*
* @dataProvider singleIntegerDataProvider
*/
public function calcOffsetWithSingleIntegerReturnsTheGivenIntegerAsString(string $number): void
{
$result = $this->subject->calcOffset($number);
self::assertSame($number, $result);
}
/**
* @test
*/
public function calcOffsetWithMultipleIntegersReturnsTheGivenIntegerCommaSeparated(): void
{
$numbers = '1,2,3';
$result = $this->subject->calcOffset($numbers);
self::assertSame($numbers, $result);
}
/**
* @test
*/
public function calcOffsetTrimsWhitespaceAroundProvidedNumbers(): void
{
$result = $this->subject->calcOffset(' 1, 2, 3 ');
self::assertSame('1,2,3', $result);
}
/**
* @return array<string, array{0: non-empty-string, 1: non-empty-string}>
*/
public function roundingDataProvider(): array
{
return [
'rounding down' => ['1.1', '1'],
'rounding up' => ['1.9', '2'],
];
}
/**
* @test
*
* @dataProvider roundingDataProvider
*/
public function calcOffsetRoundsNumbersToNearestInteger(string $input, string $expectedResult): void
{
$result = $this->subject->calcOffset($input);
self::assertSame($expectedResult, $result);
}
/**
* @return array<string, array{0: non-empty-string, 1: non-empty-string}>
*/
public function calculationDataProvider(): array
{
return [
'addition of positive numbers' => ['1+1', '2'],
'addition of negative numbers' => ['-1+-1', '-2'],
'subtraction' => ['5-2', '3'],
'multiplication' => ['2*5', '10'],
'division with whole-number result' => ['10/5', '2'],
'division with rounding up' => ['19/5', '4'],
'division with rounding down' => ['21/5', '4'],
'modulo' => ['21%5', '1'],
];
}
/**
* @test
*
* @dataProvider calculationDataProvider
*/
public function calcOffsetDoesTheProvidedCalculation(string $input, string $expectedResult): void
{
$result = $this->subject->calcOffset($input);
self::assertSame($expectedResult, $result);
}
}
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