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

+10 -10
View File
@@ -26,8 +26,8 @@ class AcceptedVouchersTest extends TestCase
amount: 100.00
));
$this->assertEquals(150.0, $acceptedVouchers->getTotalDiscount());
$this->assertCount(2, $acceptedVouchers->getVouchers());
self::assertEquals(150.0, $acceptedVouchers->getTotalDiscount());
self::assertCount(2, $acceptedVouchers->getVouchers());
}
public function testFilterVouchersByType(): void
@@ -52,17 +52,17 @@ class AcceptedVouchersTest extends TestCase
amount: 75.00
));
$this->assertCount(1, $acceptedVouchers->getPromotionalVouchers());
$this->assertCount(1, $acceptedVouchers->getPurchaseVouchers());
$this->assertCount(1, $acceptedVouchers->getGoodwillVouchers());
self::assertCount(1, $acceptedVouchers->getPromotionalVouchers());
self::assertCount(1, $acceptedVouchers->getPurchaseVouchers());
self::assertCount(1, $acceptedVouchers->getGoodwillVouchers());
}
public function testHasVouchersReturnsFalseWhenEmpty(): void
{
$acceptedVouchers = new AcceptedVouchersDto();
$this->assertFalse($acceptedVouchers->hasVouchers());
$this->assertEquals(0, $acceptedVouchers->count());
self::assertFalse($acceptedVouchers->hasVouchers());
self::assertEquals(0, $acceptedVouchers->count());
}
public function testHasVouchersReturnsTrueWhenNotEmpty(): void
@@ -75,8 +75,8 @@ class AcceptedVouchersTest extends TestCase
amount: 50.00
));
$this->assertTrue($acceptedVouchers->hasVouchers());
$this->assertEquals(1, $acceptedVouchers->count());
self::assertTrue($acceptedVouchers->hasVouchers());
self::assertEquals(1, $acceptedVouchers->count());
}
public function testFloatPrecisionHandling(): void
@@ -102,6 +102,6 @@ class AcceptedVouchersTest extends TestCase
));
// Should be exactly 100.00 with proper rounding
$this->assertEquals(100.0, $acceptedVouchers->getTotalDiscount());
self::assertEquals(100.0, $acceptedVouchers->getTotalDiscount());
}
}
+7 -7
View File
@@ -24,9 +24,9 @@ class BookingDtoTest extends TestCase
$bookingDto = new BookingDto($travel, 1);
$this->assertInstanceOf(BookingDto::class, $bookingDto);
$this->assertSame($travel, $bookingDto->travel);
$this->assertSame(BookingDto::MODE_CREATE, $bookingDto->getMode());
self::assertInstanceOf(BookingDto::class, $bookingDto);
self::assertSame($travel, $bookingDto->travel);
self::assertSame(BookingDto::MODE_CREATE, $bookingDto->getMode());
}
public function testUnserializeHandlesIntTravelId(): void
@@ -40,8 +40,8 @@ class BookingDtoTest extends TestCase
$serialized = serialize($dto);
$restored = unserialize($serialized);
$this->assertInstanceOf(BookingDto::class, $restored);
$this->assertSame(42, $restored->travel->id);
self::assertInstanceOf(BookingDto::class, $restored);
self::assertSame(42, $restored->travel->id);
}
public function testUnserializeHandlesLegacyTravelObject(): void
@@ -60,7 +60,7 @@ class BookingDtoTest extends TestCase
$dto = new BookingDto(new Travel(), 1);
$dto->__unserialize($data);
$this->assertSame($travel, $dto->travel);
$this->assertSame(42, $dto->travel->id);
self::assertSame($travel, $dto->travel);
self::assertSame(42, $dto->travel->id);
}
}
+17 -17
View File
@@ -15,7 +15,7 @@ class ParticipantDtoTest extends TestCase
$participant = new ParticipantDto();
$participant->dateOfBirth = null;
$this->assertNull($participant->getAge());
self::assertNull($participant->getAge());
}
public function testGetAgeCalculatesCurrentAgeWhenNoReferenceDateProvided(): void
@@ -26,7 +26,7 @@ class ParticipantDtoTest extends TestCase
$expectedAge = (new \DateTimeImmutable())->diff($participant->dateOfBirth)->y;
$actualAge = $participant->getAge();
$this->assertEquals($expectedAge, $actualAge);
self::assertEquals($expectedAge, $actualAge);
}
public function testGetAgeCalculatesAgeAtSpecificReferenceDate(): void
@@ -37,7 +37,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getAge($referenceDate);
$this->assertEquals(33, $result); // Still 33 years old
self::assertEquals(33, $result); // Still 33 years old
}
public function testGetAgeCalculatesAgeAtSpecificReferenceDateAfterBirthday(): void
@@ -48,7 +48,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getAge($referenceDate);
$this->assertEquals(34, $result); // Now 34 years old
self::assertEquals(34, $result); // Now 34 years old
}
public function testGetAgeCalculatesAgeForInsuranceEligibilityScenario(): void
@@ -61,7 +61,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getAge($travelStartDate);
// On 2024-08-01, they are still 34 (birthday not yet reached)
$this->assertEquals(34, $result);
self::assertEquals(34, $result);
}
public function testGetAgeCalculatesAgeForInsuranceEligibilityScenarioAfterBirthday(): void
@@ -74,7 +74,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getAge($travelStartDate);
// On 2024-12-26, they just turned 35
$this->assertEquals(35, $result);
self::assertEquals(35, $result);
}
public function testGetAgeHandlesLeapYearScenarios(): void
@@ -86,7 +86,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getAge($referenceDate);
$this->assertEquals(22, $result); // Still 22, birthday is technically next day
self::assertEquals(22, $result); // Still 22, birthday is technically next day
}
public function testGetAgeReturnsNullWithReferenceDateWhenDateOfBirthIsNull(): void
@@ -97,7 +97,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getAge($referenceDate);
$this->assertNull($result);
self::assertNull($result);
}
public function testGetAgeWithYoungParticipant(): void
@@ -109,7 +109,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getAge($referenceDate);
$this->assertEquals(4, $result);
self::assertEquals(4, $result);
}
public function testGetAgeWithElderlyParticipant(): void
@@ -121,7 +121,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getAge($referenceDate);
$this->assertEquals(84, $result);
self::assertEquals(84, $result);
}
public function testHasInsuranceReturnsFalseWhenNoInsuranceSelected(): void
@@ -131,7 +131,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->hasInsuranceSelected();
$this->assertFalse($result);
self::assertFalse($result);
}
public function testHasInsuranceReturnsTrueWhenInsuranceSelected(): void
@@ -141,7 +141,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->hasInsuranceSelected();
$this->assertTrue($result);
self::assertTrue($result);
}
public function testGetInsuranceLabelReturnsNullWhenNoInsurance(): void
@@ -151,7 +151,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getInsuranceLabel();
$this->assertNull($result);
self::assertNull($result);
}
public function testGetInsuranceLabelReturnsLabelWhenInsuranceSelected(): void
@@ -161,7 +161,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getInsuranceLabel();
$this->assertEquals('Reise-Rücktritt', $result);
self::assertEquals('Reise-Rücktritt', $result);
}
public function testGetInsurancePriceReturnsZeroWhenNoInsurance(): void
@@ -171,7 +171,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getInsurancePrice();
$this->assertEquals(0.0, $result);
self::assertEquals(0.0, $result);
}
public function testGetInsurancePriceReturnsPriceWhenInsuranceSelected(): void
@@ -181,7 +181,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getInsurancePrice();
$this->assertEquals(25.50, $result);
self::assertEquals(25.50, $result);
}
public function testGetInsurancePriceReturnsZeroWhenInsuranceHasNullPrice(): void
@@ -193,7 +193,7 @@ class ParticipantDtoTest extends TestCase
$result = $participant->getInsurancePrice();
$this->assertEquals(0.0, $result);
self::assertEquals(0.0, $result);
}
private function createInsurance(string $label = 'Test Insurance', float $price = 10.0): Insurance