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

@@ -22,24 +22,24 @@ class ParticipantAssignedRoomFieldHandlerTest extends TestCase
public function testGetFieldName(): void
{
$this->assertSame('assignedRoomId', $this->handler->getFieldName());
self::assertSame('assignedRoomId', $this->handler->getFieldName());
}
public function testGetDependencies(): void
{
$this->assertSame([], $this->handler->getDependencies());
self::assertSame([], $this->handler->getDependencies());
}
public function testShouldProcessReturnsTrueWhenFieldPresent(): void
{
$this->assertTrue($this->handler->shouldProcess(['assignedRoomId' => '1'], BookingDto::MODE_CREATE, 0));
$this->assertTrue($this->handler->shouldProcess(['assignedRoomId' => ''], BookingDto::MODE_EDIT, 5));
self::assertTrue($this->handler->shouldProcess(['assignedRoomId' => '1'], BookingDto::MODE_CREATE, 0));
self::assertTrue($this->handler->shouldProcess(['assignedRoomId' => ''], BookingDto::MODE_EDIT, 5));
}
public function testShouldProcessReturnsFalseWhenFieldNotPresent(): void
{
$this->assertFalse($this->handler->shouldProcess([], BookingDto::MODE_CREATE, 0));
$this->assertFalse($this->handler->shouldProcess(['some' => 'data'], BookingDto::MODE_EDIT, 5));
self::assertFalse($this->handler->shouldProcess([], BookingDto::MODE_CREATE, 0));
self::assertFalse($this->handler->shouldProcess(['some' => 'data'], BookingDto::MODE_EDIT, 5));
}
public function testProcessFieldWithoutParticipant(): void
@@ -67,7 +67,7 @@ class ParticipantAssignedRoomFieldHandlerTest extends TestCase
$this->handler->processField($submittedData, $bookingDto, 0);
$this->assertSame(1, $participant->assignedRoomId);
self::assertSame(1, $participant->assignedRoomId);
}
public function testProcessFieldUnassignsParticipantWhenRoomIdIsEmpty(): void
@@ -83,7 +83,7 @@ class ParticipantAssignedRoomFieldHandlerTest extends TestCase
$this->handler->processField($submittedData, $bookingDto, 0);
$this->assertNull($participant->assignedRoomId);
self::assertNull($participant->assignedRoomId);
}
public function testProcessFieldUnassignsParticipantWhenRoomIdIsNull(): void
@@ -99,7 +99,7 @@ class ParticipantAssignedRoomFieldHandlerTest extends TestCase
$this->handler->processField($submittedData, $bookingDto, 0);
$this->assertNull($participant->assignedRoomId);
self::assertNull($participant->assignedRoomId);
}
public function testProcessFieldUnassignsHighestIndexParticipantWhenRoomAtCapacity(): void
@@ -125,9 +125,9 @@ class ParticipantAssignedRoomFieldHandlerTest extends TestCase
$this->handler->processField($submittedData, $bookingDto, 2);
// Participant 1 (highest index with room 1) should be unassigned
$this->assertSame(1, $participant0->assignedRoomId); // Still assigned (applicant protection)
$this->assertNull($participant1->assignedRoomId); // Unassigned
$this->assertSame(1, $participant2->assignedRoomId); // Newly assigned
self::assertSame(1, $participant0->assignedRoomId); // Still assigned (applicant protection)
self::assertNull($participant1->assignedRoomId); // Unassigned
self::assertSame(1, $participant2->assignedRoomId); // Newly assigned
}
public function testProcessFieldGeneratesWarningNotificationForUnassignedParticipant(): void
@@ -151,13 +151,13 @@ class ParticipantAssignedRoomFieldHandlerTest extends TestCase
// Participant 1 should have a warning notification
$notifications = $participant1->notifications;
$this->assertCount(1, $notifications);
self::assertCount(1, $notifications);
// Get first notification (notifications are keyed by hash, not numeric index)
$firstNotification = reset($notifications);
$this->assertSame('warning', $firstNotification['type']);
$this->assertStringContainsString('Doppelzimmer', $firstNotification['message']);
$this->assertStringContainsString('wurde von', $firstNotification['message']);
$this->assertStringContainsString('entfernt', $firstNotification['message']);
self::assertSame('warning', $firstNotification['type']);
self::assertStringContainsString('Doppelzimmer', $firstNotification['message']);
self::assertStringContainsString('wurde von', $firstNotification['message']);
self::assertStringContainsString('entfernt', $firstNotification['message']);
}
public function testProcessFieldDoesNotGenerateNotificationForAssignedParticipant(): void
@@ -180,7 +180,7 @@ class ParticipantAssignedRoomFieldHandlerTest extends TestCase
$this->handler->processField($submittedData, $bookingDto, 2);
// Participant 2 (the one being assigned) should NOT have a notification (user-initiated action)
$this->assertEmpty($participant2->notifications);
self::assertEmpty($participant2->notifications);
}
public function testProcessFieldHandlesRoomChangeWithoutConflict(): void
@@ -203,9 +203,9 @@ class ParticipantAssignedRoomFieldHandlerTest extends TestCase
$this->handler->processField($submittedData, $bookingDto, 0);
// Both should remain assigned (participant 0's own slot was freed, so no conflict)
$this->assertSame(1, $participant0->assignedRoomId);
$this->assertSame(1, $participant1->assignedRoomId);
$this->assertEmpty($participant1->notifications);
self::assertSame(1, $participant0->assignedRoomId);
self::assertSame(1, $participant1->assignedRoomId);
self::assertEmpty($participant1->notifications);
}
public function testProcessFieldUnassignsMultipleParticipantsWhenNeeded(): void
@@ -234,10 +234,10 @@ class ParticipantAssignedRoomFieldHandlerTest extends TestCase
// All three participants with room 1 should be unassigned (highest indices first: 2, 1, 0)
// But we only need to unassign enough to make space (3 participants, only 1 space needed)
$this->assertNull($participant2->assignedRoomId); // Highest index, unassigned first
$this->assertNull($participant1->assignedRoomId); // Second highest, unassigned second
$this->assertNull($participant0->assignedRoomId); // Third highest, unassigned third
$this->assertSame(1, $participant3->assignedRoomId); // Newly assigned
self::assertNull($participant2->assignedRoomId); // Highest index, unassigned first
self::assertNull($participant1->assignedRoomId); // Second highest, unassigned second
self::assertNull($participant0->assignedRoomId); // Third highest, unassigned third
self::assertSame(1, $participant3->assignedRoomId); // Newly assigned
}
public function testProcessFieldHandlesNoConflictWithMultipleRoomQuantities(): void
@@ -265,13 +265,13 @@ class ParticipantAssignedRoomFieldHandlerTest extends TestCase
$this->handler->processField($submittedData, $bookingDto, 3);
// All should remain assigned (4 beds available, 4 participants)
$this->assertSame(1, $participant0->assignedRoomId);
$this->assertSame(1, $participant1->assignedRoomId);
$this->assertSame(1, $participant2->assignedRoomId);
$this->assertSame(1, $participant3->assignedRoomId);
$this->assertEmpty($participant0->notifications);
$this->assertEmpty($participant1->notifications);
$this->assertEmpty($participant2->notifications);
self::assertSame(1, $participant0->assignedRoomId);
self::assertSame(1, $participant1->assignedRoomId);
self::assertSame(1, $participant2->assignedRoomId);
self::assertSame(1, $participant3->assignedRoomId);
self::assertEmpty($participant0->notifications);
self::assertEmpty($participant1->notifications);
self::assertEmpty($participant2->notifications);
}
public function testProcessFieldHandlesComplexScenarioWithMultipleRoomTypes(): void
@@ -301,10 +301,10 @@ class ParticipantAssignedRoomFieldHandlerTest extends TestCase
$this->handler->processField($submittedData, $bookingDto, 3);
// Participant 1 (highest index with room 1) should be unassigned
$this->assertSame(1, $participant0->assignedRoomId);
$this->assertNull($participant1->assignedRoomId); // Unassigned
$this->assertSame(2, $participant2->assignedRoomId); // Still in Einzelzimmer
$this->assertSame(1, $participant3->assignedRoomId); // Newly assigned to Doppelzimmer
self::assertSame(1, $participant0->assignedRoomId);
self::assertNull($participant1->assignedRoomId); // Unassigned
self::assertSame(2, $participant2->assignedRoomId); // Still in Einzelzimmer
self::assertSame(1, $participant3->assignedRoomId); // Newly assigned to Doppelzimmer
}
public function testProcessFieldHandlesEdgeCaseWhenRoomNotFoundInSelections(): void
@@ -322,7 +322,7 @@ class ParticipantAssignedRoomFieldHandlerTest extends TestCase
$this->handler->processField($submittedData, $bookingDto, 0);
// Should still assign (no conflict detection possible, but assignment proceeds)
$this->assertSame(999, $participant->assignedRoomId);
self::assertSame(999, $participant->assignedRoomId);
}
/**