chore: major code cleanup and type safety using phpstan

This commit is contained in:
Björn Fromme committed 2026-04-16 17:11:16 +02:00
1 parent 060cbea9da
commit 3da73d626b
103 files changed
+976 -1192

No files matched your search

@@ -40,60 +40,60 @@ class InsuranceParserTest extends TestCase
$insurances = $this->parser->parse($crawler);
// Test all insurances are included (2 regular + 1 complementary + 1 package = 4 total)
$this->assertCount(4, $insurances);
self::assertCount(4, $insurances);
// Test travel cancellation insurance (RRV)
$cancellationInsurance = $insurances[178917];
$this->assertEquals(178917, $cancellationInsurance->id);
$this->assertEquals('903100', $cancellationInsurance->code);
$this->assertEquals('Reise-Rücktritt', $cancellationInsurance->label);
$this->assertEquals('RRV', $cancellationInsurance->subType);
$this->assertEquals(5.0, $cancellationInsurance->price);
$this->assertFalse($cancellationInsurance->familyInsurance);
$this->assertFalse($cancellationInsurance->package);
$this->assertFalse($cancellationInsurance->complementary);
$cancellationInsurance = $insurances['178917'];
self::assertEquals(178917, $cancellationInsurance->id);
self::assertEquals('903100', $cancellationInsurance->code);
self::assertEquals('Reise-Rücktritt', $cancellationInsurance->label);
self::assertEquals('RRV', $cancellationInsurance->subType);
self::assertEquals(5.0, $cancellationInsurance->price);
self::assertFalse($cancellationInsurance->familyInsurance);
self::assertFalse($cancellationInsurance->package);
self::assertFalse($cancellationInsurance->complementary);
// Test travel protection insurance (PAK) with family flag
$protectionInsurance = $insurances[177236];
$this->assertEquals(177236, $protectionInsurance->id);
$this->assertEquals('913320', $protectionInsurance->code);
$this->assertEquals('Reiseschutz Platin', $protectionInsurance->label); // "Auto/Bahn/Bus (Europa)" is normalized away
$this->assertEquals('PAK', $protectionInsurance->subType);
$this->assertEquals(9.0, $protectionInsurance->price);
$this->assertTrue($protectionInsurance->familyInsurance);
$this->assertFalse($protectionInsurance->package);
$this->assertFalse($protectionInsurance->complementary);
$protectionInsurance = $insurances['177236'];
self::assertEquals(177236, $protectionInsurance->id);
self::assertEquals('913320', $protectionInsurance->code);
self::assertEquals('Reiseschutz Platin', $protectionInsurance->label); // "Auto/Bahn/Bus (Europa)" is normalized away
self::assertEquals('PAK', $protectionInsurance->subType);
self::assertEquals(9.0, $protectionInsurance->price);
self::assertTrue($protectionInsurance->familyInsurance);
self::assertFalse($protectionInsurance->package);
self::assertFalse($protectionInsurance->complementary);
// Test deductible insurance (OHN) - IS included but marked as complementary
$deductibleInsurance = $insurances[177270];
$this->assertEquals(177270, $deductibleInsurance->id);
$this->assertEquals('903551', $deductibleInsurance->code);
$this->assertEquals('Selbstbehaltübernahme', $deductibleInsurance->label);
$this->assertEquals('OHN', $deductibleInsurance->subType);
$this->assertEquals(5.0, $deductibleInsurance->price);
$this->assertFalse($deductibleInsurance->familyInsurance);
$this->assertFalse($deductibleInsurance->package);
$this->assertTrue($deductibleInsurance->complementary); // Marked as complementary
$deductibleInsurance = $insurances['177270'];
self::assertEquals(177270, $deductibleInsurance->id);
self::assertEquals('903551', $deductibleInsurance->code);
self::assertEquals('Selbstbehaltübernahme', $deductibleInsurance->label);
self::assertEquals('OHN', $deductibleInsurance->subType);
self::assertEquals(5.0, $deductibleInsurance->price);
self::assertFalse($deductibleInsurance->familyInsurance);
self::assertFalse($deductibleInsurance->package);
self::assertTrue($deductibleInsurance->complementary); // Marked as complementary
// Test package - should be family insurance because it contains a family insurance (177236)
$package = $insurances['P1000320'];
$this->assertEquals('P1000320', $package->id);
$this->assertEquals('Reiseschutz Platin + Selbstbehaltübernahme', $package->label); // "Auto/Bahn/Bus (Europa)" is normalized away
$this->assertNull($package->subType); // Packages don't have subtypes
$this->assertEquals(14.0, $package->price);
$this->assertTrue($package->familyInsurance); // Should be true because it contains family insurance 177236
$this->assertTrue($package->package);
$this->assertEquals([177236, 177270], $package->containedInsuranceIds);
self::assertEquals('P1000320', $package->id);
self::assertEquals('Reiseschutz Platin + Selbstbehaltübernahme', $package->label); // "Auto/Bahn/Bus (Europa)" is normalized away
self::assertNull($package->subType); // Packages don't have subtypes
self::assertEquals(14.0, $package->price);
self::assertTrue($package->familyInsurance); // Should be true because it contains family insurance 177236
self::assertTrue($package->package);
self::assertEquals(['177236', '177270'], $package->containedInsuranceIds);
// Test containedInsurances array is populated with actual Insurance objects
$this->assertCount(2, $package->containedInsurances);
$this->assertEquals(177236, $package->containedInsurances[0]->id);
$this->assertEquals(177270, $package->containedInsurances[1]->id);
self::assertCount(2, $package->containedInsurances);
self::assertEquals(177236, $package->containedInsurances[0]->id);
self::assertEquals(177270, $package->containedInsurances[1]->id);
// Test URL aggregation from contained insurances
$this->assertEquals(['https://example.com/info2', 'https://example.com/info3'], $package->getAllUrlsInfo());
$this->assertEquals(['https://example.com/product2', 'https://example.com/product3'], $package->getAllUrlsProductInfo());
$this->assertEquals(['https://example.com/terms2', 'https://example.com/terms3'], $package->getAllUrlsTerms());
self::assertEquals(['https://example.com/info2', 'https://example.com/info3'], $package->getAllUrlsInfo());
self::assertEquals(['https://example.com/product2', 'https://example.com/product3'], $package->getAllUrlsProductInfo());
self::assertEquals(['https://example.com/terms2', 'https://example.com/terms3'], $package->getAllUrlsTerms());
}
public function testParsePackageWithoutSubtype(): void
@@ -115,14 +115,14 @@ class InsuranceParserTest extends TestCase
$crawler = new Crawler($xmlContent);
$insurances = $this->parser->parse($crawler);
$this->assertCount(2, $insurances);
self::assertCount(2, $insurances);
// Test package has no subType but has familyInsurance flag
$package = $insurances['P1000320'];
$this->assertEquals('P1000320', $package->id);
$this->assertNull($package->subType);
$this->assertTrue($package->familyInsurance);
$this->assertTrue($package->package);
self::assertEquals('P1000320', $package->id);
self::assertNull($package->subType);
self::assertTrue($package->familyInsurance);
self::assertTrue($package->package);
}
public function testParseInsuranceWithNullSubtype(): void
@@ -137,12 +137,12 @@ class InsuranceParserTest extends TestCase
$crawler = new Crawler($xmlContent);
$insurances = $this->parser->parse($crawler);
$this->assertCount(1, $insurances);
self::assertCount(1, $insurances);
$insurance = $insurances[178917];
$this->assertEquals(178917, $insurance->id);
$this->assertNull($insurance->subType); // Missing unterart attribute should result in null
$this->assertFalse($insurance->package);
$insurance = $insurances['178917'];
self::assertEquals(178917, $insurance->id);
self::assertNull($insurance->subType); // Missing unterart attribute should result in null
self::assertFalse($insurance->package);
}
public function testParseEmptyXml(): void
@@ -158,7 +158,7 @@ class InsuranceParserTest extends TestCase
$crawler = new Crawler($xmlContent);
$insurances = $this->parser->parse($crawler);
$this->assertEmpty($insurances);
self::assertEmpty($insurances);
}
public function testParseZusatzversicherungFiltering(): void
@@ -183,15 +183,15 @@ class InsuranceParserTest extends TestCase
$insurances = $this->parser->parse($crawler);
// Should include: normal insurance (178917), both complementary insurances (177270, 999999), and package (P1000320)
$this->assertCount(4, $insurances);
$this->assertArrayHasKey(178917, $insurances);
$this->assertArrayHasKey(177270, $insurances);
$this->assertArrayHasKey(999999, $insurances);
$this->assertArrayHasKey('P1000320', $insurances);
self::assertCount(4, $insurances);
self::assertArrayHasKey('178917', $insurances);
self::assertArrayHasKey('177270', $insurances);
self::assertArrayHasKey('999999', $insurances);
self::assertArrayHasKey('P1000320', $insurances);
// Verify complementary flags
$this->assertFalse($insurances[178917]->complementary); // Normal insurance
$this->assertTrue($insurances[177270]->complementary); // Complementary insurance
$this->assertTrue($insurances[999999]->complementary); // Complementary insurance
self::assertFalse($insurances['178917']->complementary); // Normal insurance
self::assertTrue($insurances['177270']->complementary); // Complementary insurance
self::assertTrue($insurances['999999']->complementary); // Complementary insurance
}
}