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

+60 -39
View File
@@ -42,8 +42,8 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getSelectableInsurances($travel);
$this->assertCount(1, $result);
$this->assertSame($regularInsurance, $result[0]);
self::assertCount(1, $result);
self::assertSame($regularInsurance, $result[0]);
}
public function testGetSelectableInsurancesCachesResults(): void
@@ -58,7 +58,7 @@ class InsuranceManagerTest extends TestCase
$result1 = $this->service->getSelectableInsurances($travel);
$result2 = $this->service->getSelectableInsurances($travel);
$this->assertSame($result1, $result2);
self::assertSame($result1, $result2);
}
public function testGetEligibleInsurancesWithMatchingCriteria(): void
@@ -81,8 +81,8 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertCount(1, $result);
$this->assertContains($insurance, $result);
self::assertCount(1, $result);
self::assertContains($insurance, $result);
}
public function testGetEligibleInsurancesExcludesInsuranceWithAgeTooYoung(): void
@@ -94,7 +94,7 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertEmpty($result);
self::assertEmpty($result);
}
public function testGetEligibleInsurancesExcludesInsuranceWithAgeTooOld(): void
@@ -106,7 +106,7 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertEmpty($result);
self::assertEmpty($result);
}
public function testGetEligibleInsurancesExcludesInsuranceWithTravelDateTooEarly(): void
@@ -121,7 +121,7 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertEmpty($result);
self::assertEmpty($result);
}
public function testGetEligibleInsurancesExcludesInsuranceWithTravelDateTooLate(): void
@@ -136,7 +136,7 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertEmpty($result);
self::assertEmpty($result);
}
public function testGetEligibleInsurancesExcludesInsuranceWithBookingDateTooEarly(): void
@@ -151,7 +151,7 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertEmpty($result);
self::assertEmpty($result);
}
public function testGetEligibleInsurancesExcludesInsuranceWithBookingDateTooLate(): void
@@ -166,7 +166,7 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertEmpty($result);
self::assertEmpty($result);
}
public function testGetEligibleInsurancesExcludesInsuranceWithTravelPriceTooLow(): void
@@ -179,7 +179,7 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertEmpty($result);
self::assertEmpty($result);
}
public function testGetEligibleInsurancesExcludesInsuranceWithTravelPriceTooHigh(): void
@@ -192,7 +192,7 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertEmpty($result);
self::assertEmpty($result);
}
public function testGetEligibleInsurancesExcludesInsuranceWithTravelDurationTooShort(): void
@@ -204,7 +204,7 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertEmpty($result);
self::assertEmpty($result);
}
public function testGetEligibleInsurancesExcludesInsuranceWithTravelDurationTooLong(): void
@@ -216,7 +216,7 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertEmpty($result);
self::assertEmpty($result);
}
public function testGetEligibleInsurancesHandlesParticipantWithoutBirthDate(): void
@@ -232,9 +232,9 @@ class InsuranceManagerTest extends TestCase
// Participants without birth date should have insurances available
// (field visibility is controlled by field state conditions, not service logic)
$this->assertNotEmpty($result);
$this->assertCount(1, $result);
$this->assertSame($insurance, $result[0]);
self::assertNotEmpty($result);
self::assertCount(1, $result);
self::assertSame($insurance, $result[0]);
}
public function testGetEligibleInsurancesWithNullConstraints(): void
@@ -247,8 +247,8 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertCount(1, $result);
$this->assertContains($insurance, $result);
self::assertCount(1, $result);
self::assertContains($insurance, $result);
}
public function testGetEligibleInsurancesWithMultipleInsurances(): void
@@ -263,10 +263,10 @@ class InsuranceManagerTest extends TestCase
$insurances = [$eligibleInsurance1, $eligibleInsurance2, $ineligibleInsurance];
$result = $this->service->getEligibleInsurances($insurances, $participant, $booking, 500.0);
$this->assertCount(2, $result);
$this->assertContains($eligibleInsurance1, $result);
$this->assertContains($eligibleInsurance2, $result);
$this->assertNotContains($ineligibleInsurance, $result);
self::assertCount(2, $result);
self::assertContains($eligibleInsurance1, $result);
self::assertContains($eligibleInsurance2, $result);
self::assertNotContains($ineligibleInsurance, $result);
}
public function testGetEligibleInsurancesWithAgeExactlyAtBoundary(): void
@@ -278,8 +278,8 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertCount(1, $result);
$this->assertContains($insurance, $result);
self::assertCount(1, $result);
self::assertContains($insurance, $result);
}
public function testGetEligibleInsurancesWithTravelDurationExactlyAtBoundary(): void
@@ -291,8 +291,8 @@ class InsuranceManagerTest extends TestCase
$result = $this->service->getEligibleInsurances([$insurance], $participant, $booking, 500.0);
$this->assertCount(1, $result);
$this->assertContains($insurance, $result);
self::assertCount(1, $result);
self::assertContains($insurance, $result);
}
public function testFilterByTypeForPackages(): void
@@ -319,9 +319,9 @@ class InsuranceManagerTest extends TestCase
$insurances = [$packageInsurance1, $packageInsurance2, $differentPackage];
$result = $this->service->filterByType($insurances, $packageInsurance1);
$this->assertCount(2, $result);
$this->assertContains($packageInsurance1, $result);
$this->assertContains($packageInsurance2, $result);
self::assertCount(2, $result);
self::assertContains($packageInsurance1, $result);
self::assertContains($packageInsurance2, $result);
}
public function testFilterByTypeForIndividualInsurances(): void
@@ -348,9 +348,9 @@ class InsuranceManagerTest extends TestCase
$insurances = [$insurance1, $insurance2, $differentType];
$result = $this->service->filterByType($insurances, $insurance1);
$this->assertCount(2, $result);
$this->assertContains($insurance1, $result);
$this->assertContains($insurance2, $result);
self::assertCount(2, $result);
self::assertContains($insurance1, $result);
self::assertContains($insurance2, $result);
}
public function testReassignInsuranceForPriceChange(): void
@@ -384,7 +384,7 @@ class InsuranceManagerTest extends TestCase
500.0
);
$this->assertSame($newTierInsurance, $result);
self::assertSame($newTierInsurance, $result);
}
public function testBatchAssignInsuranceToParticipants(): void
@@ -420,9 +420,9 @@ class InsuranceManagerTest extends TestCase
$participantPrices
);
$this->assertCount(2, $result);
$this->assertNotNull($result[0]);
$this->assertNotNull($result[1]);
self::assertCount(2, $result);
self::assertNotNull($result[0]);
self::assertNotNull($result[1]);
}
private function createParticipant(string $dateOfBirth): ParticipantDto
@@ -452,6 +452,9 @@ class InsuranceManagerTest extends TestCase
return $travel;
}
/**
* @param array<string, mixed> $properties
*/
private function createInsurance(array $properties = []): Insurance
{
$insurance = new Insurance();
@@ -462,7 +465,25 @@ class InsuranceManagerTest extends TestCase
$insurance->familyInsurance = false;
foreach ($properties as $property => $value) {
$insurance->$property = $value;
match ($property) {
'id' => $insurance->id = (string) $value,
'complementary' => $insurance->complementary = (bool) $value,
'package' => $insurance->package = (bool) $value,
'familyInsurance' => $insurance->familyInsurance = (bool) $value,
'label' => $insurance->label = (string) $value,
'subType' => $insurance->subType = null === $value ? null : (string) $value,
'travelDateFrom' => $insurance->travelDateFrom = $value,
'travelDateTo' => $insurance->travelDateTo = $value,
'bookingDateFrom' => $insurance->bookingDateFrom = $value,
'bookingDateTo' => $insurance->bookingDateTo = $value,
'travelPriceFrom' => $insurance->travelPriceFrom = null === $value ? null : (float) $value,
'travelPriceTo' => $insurance->travelPriceTo = null === $value ? null : (float) $value,
'travelDurationFrom' => $insurance->travelDurationFrom = null === $value ? null : (int) $value,
'travelDurationTo' => $insurance->travelDurationTo = null === $value ? null : (int) $value,
'ageFrom' => $insurance->ageFrom = null === $value ? null : (int) $value,
'ageTo' => $insurance->ageTo = null === $value ? null : (int) $value,
default => null,
};
}
return $insurance;