From 9c6ada1a1cc0523893e97461ef88ed998f1891a6 Mon Sep 17 00:00:00 2001 From: fds2610-bot Date: Mon, 2 Nov 2026 08:08:19 +0100 Subject: [PATCH] Fix the phpstan errors on master The baseline of #603 was generated before #594, #598 and #601 were merged, so master reports 19 errors. They are fixed in the code instead of being added to the baseline: - Return types for the new test methods and HKWPDv6::setPaginationToken(). - Array value types for GetSEPAAccounts::__serialize()/__unserialize() and the CAMT data provider. - GetSEPAAccountsTest builds the UPD from HIUPDv6 segments, as UPD::$hiupd expects. - HIUPDTest converts its examples in a typed helper (self:: instead of static::), which also clears the six baselined parse() errors. - Drop the two CAMT baseline entries that #601 made obsolete. --- Tests/Unit/Action/GetSEPAAccountsTest.php | 15 ++++++----- Tests/Unit/CAMT/CAMTStructuredFieldsTest.php | 2 ++ Tests/Unit/Segment/HIUPDTest.php | 28 ++++++++++++-------- Tests/Unit/Segment/HKWPDTest.php | 4 +-- phpstan-baseline.neon | 18 ------------- src/Action/GetSEPAAccounts.php | 2 ++ src/Segment/WPD/HKWPDv6.php | 2 +- 7 files changed, 32 insertions(+), 39 deletions(-) diff --git a/Tests/Unit/Action/GetSEPAAccountsTest.php b/Tests/Unit/Action/GetSEPAAccountsTest.php index 09694868..a69ea25f 100644 --- a/Tests/Unit/Action/GetSEPAAccountsTest.php +++ b/Tests/Unit/Action/GetSEPAAccountsTest.php @@ -7,6 +7,7 @@ use Fhp\Protocol\Message; use Fhp\Protocol\UPD; use Fhp\Segment\BaseSegment; +use Fhp\Segment\HIUPD\HIUPDv6; use Fhp\Segment\SPA\HKSPAv2; /** @@ -24,7 +25,7 @@ class GetSEPAAccountsTest extends ActionTestCase . 'i:0;a:5:{i:0;a:1:{i:0;i:3;}i:1;N;i:2;N;i:3;N;i:4;N;}i:1;N;' . 'i:2;a:1:{i:0;O:23:"Fhp\\Segment\\SPA\\HKSPAv2":1:{i:0;s:10:"HKSPA:3:2\'";}}}'; - public function testAnnotatesAccountsFromTheUpd() + public function testAnnotatesAccountsFromTheUpd(): void { $action = GetSEPAAccounts::create(); self::nextRequest($action, self::createBpd(self::hispas()), self::createUpd()); @@ -47,7 +48,7 @@ public function testAnnotatesAccountsFromTheUpd() $this->assertSame(10, $savings->getAccountType()); } - public function testLeavesAccountsWithoutHiupdUnannotated() + public function testLeavesAccountsWithoutHiupdUnannotated(): void { $upd = new UPD(); $upd->hiupd = []; @@ -65,7 +66,7 @@ public function testLeavesAccountsWithoutHiupdUnannotated() } } - public function testWorksWithoutUpd() + public function testWorksWithoutUpd(): void { $action = GetSEPAAccounts::create(); self::nextRequest($action, self::createBpd(self::hispas())); @@ -80,7 +81,7 @@ public function testWorksWithoutUpd() * the FinTs instance that completes it may come from persist(true), which contains no UPD. So the UPD captured in * createRequest() has to survive that round trip for the accounts to be annotated afterwards. */ - public function testUpdSurvivesSerialization() + public function testUpdSurvivesSerialization(): void { $action = GetSEPAAccounts::create(); $requestSegments = self::nextRequest($action, self::createBpd(self::hispas()), self::createUpd()); @@ -95,7 +96,7 @@ public function testUpdSurvivesSerialization() $this->assertSame('Girokonto Komfort', $giro->getProductName()); } - public function testUnserializesActionsSerializedWithoutUpd() + public function testUnserializesActionsSerializedWithoutUpd(): void { /** @var GetSEPAAccounts $restored */ $restored = unserialize(self::SERIALIZED_BY_DD2A7F2); @@ -130,10 +131,10 @@ private static function createUpd(): UPD { $upd = new UPD(); $upd->hiupd = [ - BaseSegment::parse( + HIUPDv6::parse( "HIUPD:7:6:4+5407324931::280:50010517+DE44500105175407324931+9999999999+1+EUR+Mustermann+Max+Girokonto Komfort++HKSAK:1+HKKAZ:1+HKSPA:1'" ), - BaseSegment::parse( + HIUPDv6::parse( "HIUPD:8:6:4+0123456789::280:50010517++9999999999+10+EUR+Mustermann++Sparkonto++HKSAK:1+HKKAZ:1+HKSPA:1'" ), ]; diff --git a/Tests/Unit/CAMT/CAMTStructuredFieldsTest.php b/Tests/Unit/CAMT/CAMTStructuredFieldsTest.php index 5b1fa506..5993e1af 100644 --- a/Tests/Unit/CAMT/CAMTStructuredFieldsTest.php +++ b/Tests/Unit/CAMT/CAMTStructuredFieldsTest.php @@ -17,6 +17,7 @@ protected function setUp(): void /** * @dataProvider UstrdProvider + * @param array $expectedStructuredTags */ public function testExtractStructuredFieldsFromText(string $text, array $expectedStructuredTags): void { @@ -27,6 +28,7 @@ public function testExtractStructuredFieldsFromText(string $text, array $expecte self::assertSame($expectedStructuredTags, $fields); } + /** @return list}> */ public static function UstrdProvider(): array { return [ diff --git a/Tests/Unit/Segment/HIUPDTest.php b/Tests/Unit/Segment/HIUPDTest.php index 2cfca14e..ca204d9d 100644 --- a/Tests/Unit/Segment/HIUPDTest.php +++ b/Tests/Unit/Segment/HIUPDTest.php @@ -22,9 +22,15 @@ class HIUPDTest extends \PHPUnit\Framework\TestCase "HIUPD:17:4:4+1234568::280:10020030+12345+DEM+Ernst Müller++Sparkonto 2000++HKPRO:1+HKSAK:0+HKISA:1+HKSSP:0+HKUEB:2:Z:1000,:DEM:7+HKKAN:1+HKKAZ:1+HKSAL:2'", ]; + /** The examples in ISO-8859-1, as a bank would send them. */ + private static function hbci22Example(int $index): string + { + return mb_convert_encoding(self::HBCI22_EXAMPLES[$index], 'ISO-8859-1', 'UTF-8'); + } + public function testParseHBCI22Example1() { - $parsed = HIUPDv4::parse(mb_convert_encoding(static::HBCI22_EXAMPLES[0], 'ISO-8859-1', 'UTF-8')); + $parsed = HIUPDv4::parse(self::hbci22Example(0)); $this->assertSame(16, $parsed->segmentkopf->segmentnummer); $this->assertSame(4, $parsed->segmentkopf->segmentversion); $this->assertSame('1234567', $parsed->kontoverbindung->kontonummer); @@ -46,20 +52,20 @@ public function testParseHBCI22Example1() public function testValidateHBCI22Example1() { - $parsed = HIUPDv4::parse(mb_convert_encoding(static::HBCI22_EXAMPLES[0], 'ISO-8859-1', 'UTF-8')); + $parsed = HIUPDv4::parse(self::hbci22Example(0)); $parsed->validate(); // Should not throw. $this->assertTrue(true); } public function testSerializeHBCI22Example1() { - $parsed = HIUPDv4::parse(mb_convert_encoding(static::HBCI22_EXAMPLES[0], 'ISO-8859-1', 'UTF-8')); - $this->assertEquals(mb_convert_encoding(static::HBCI22_EXAMPLES[0], 'ISO-8859-1', 'UTF-8'), $parsed->serialize()); + $parsed = HIUPDv4::parse(self::hbci22Example(0)); + $this->assertEquals(self::hbci22Example(0), $parsed->serialize()); } public function testParseHBCI22Example2() { - $parsed = HIUPDv4::parse(mb_convert_encoding(static::HBCI22_EXAMPLES[1], 'ISO-8859-1', 'UTF-8')); + $parsed = HIUPDv4::parse(self::hbci22Example(1)); $this->assertSame('1234568', $parsed->kontoverbindung->kontonummer); $this->assertSame('Sparkonto 2000', $parsed->kontoproduktbezeichnung); $this->assertNull($parsed->kontolimit); @@ -75,24 +81,24 @@ public function testParseHBCI22Example2() public function testValidateHBCI22Example2() { - $parsed = HIUPDv4::parse(mb_convert_encoding(static::HBCI22_EXAMPLES[1], 'ISO-8859-1', 'UTF-8')); + $parsed = HIUPDv4::parse(self::hbci22Example(1)); $parsed->validate(); // Should not throw. $this->assertTrue(true); } public function testSerializeHBCI22Example2() { - $parsed = HIUPDv4::parse(mb_convert_encoding(static::HBCI22_EXAMPLES[1], 'ISO-8859-1', 'UTF-8')); - $this->assertEquals(mb_convert_encoding(static::HBCI22_EXAMPLES[1], 'ISO-8859-1', 'UTF-8'), $parsed->serialize()); + $parsed = HIUPDv4::parse(self::hbci22Example(1)); + $this->assertEquals(self::hbci22Example(1), $parsed->serialize()); } - public function testAccountHolderNameWithoutSecondNameField() + public function testAccountHolderNameWithoutSecondNameField(): void { - $parsed = HIUPDv4::parse(mb_convert_encoding(static::HBCI22_EXAMPLES[0], 'ISO-8859-1', 'UTF-8')); + $parsed = HIUPDv4::parse(self::hbci22Example(0)); $this->assertSame('Ernst Müller', $parsed->getAccountHolderName()); } - public function testAccountHolderNameJoinsBothNameFields() + public function testAccountHolderNameJoinsBothNameFields(): void { $parsed = HIUPDv6::parse( "HIUPD:10:6:4+1234567890::280:60050101+DE02600501011234567890+9999999999+1+EUR+Mustermann+Max+Giro++HKSAK:1'" diff --git a/Tests/Unit/Segment/HKWPDTest.php b/Tests/Unit/Segment/HKWPDTest.php index 6da4bf91..da621bac 100644 --- a/Tests/Unit/Segment/HKWPDTest.php +++ b/Tests/Unit/Segment/HKWPDTest.php @@ -14,7 +14,7 @@ */ class HKWPDTest extends TestCase { - public function testParametersOfVersion6() + public function testParametersOfVersion6(): void { /** @var HIWPDSv6 $hiwpds */ $hiwpds = Parser::parseSegment("HIWPDS:60:6:3+1+1+0+N:N:N'", HIWPDSv6::class); @@ -24,7 +24,7 @@ public function testParametersOfVersion6() $this->assertFalse($hiwpds->getParameter()->getKursqualitaetWaehlbar()); } - public function testRequestOfVersion6() + public function testRequestOfVersion6(): void { $hkwpd = HKWPDv6::create(KtvV3::create('502022353', null, Kik::create('12030000'))); $hkwpd->setSegmentNumber(3); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index be8e1292..c5d78a34 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -996,12 +996,6 @@ parameters: count: 6 path: Tests/Unit/Segment/HIUPDTest.php - - - message: '#^Parameter \#1 \$rawSegment of static method Fhp\\Segment\\BaseSegment\:\:parse\(\) expects string, array\|string given\.$#' - identifier: argument.type - count: 6 - path: Tests/Unit/Segment/HIUPDTest.php - - message: '#^Parameter \#2 \$haystack of method PHPUnit\\Framework\\Assert\:\:assertCount\(\) expects Countable\|iterable, array\\|null given\.$#' identifier: argument.type @@ -1746,18 +1740,6 @@ parameters: count: 2 path: src/CAMT/CAMT.php - - - message: '#^Cannot access offset 0 on array\\|false\|null\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/CAMT/CAMT.php - - - - message: '#^Expression on left side of \?\? is not nullable\.$#' - identifier: nullCoalesce.expr - count: 1 - path: src/CAMT/CAMT.php - - message: '#^Method Fhp\\CAMT\\CAMT\:\:extractStructuredFieldsFromText\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/src/Action/GetSEPAAccounts.php b/src/Action/GetSEPAAccounts.php index fddea095..a4df8901 100644 --- a/src/Action/GetSEPAAccounts.php +++ b/src/Action/GetSEPAAccounts.php @@ -59,6 +59,7 @@ public function serialize(): string return serialize($this->__serialize()); } + /** @return array */ public function __serialize(): array { return [ @@ -78,6 +79,7 @@ public function unserialize($serialized) self::__unserialize(unserialize($serialized)); } + /** @param array $serialized */ public function __unserialize(array $serialized): void { // Actions serialized before the UPD travelled along consist of the PaginateableAction state only. diff --git a/src/Segment/WPD/HKWPDv6.php b/src/Segment/WPD/HKWPDv6.php index 90410943..d0348083 100644 --- a/src/Segment/WPD/HKWPDv6.php +++ b/src/Segment/WPD/HKWPDv6.php @@ -28,7 +28,7 @@ public static function create(\Fhp\Segment\Common\KtvV3 $ktv): HKWPDv6 return $result; } - public function setPaginationToken(string $paginationToken) + public function setPaginationToken(string $paginationToken): void { $this->aufsetzpunkt = $paginationToken; }