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,6 +10,7 @@ use App\BusProNet\Model\Travel;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Form\Service\ParticipantVegFieldHandler;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class ParticipantVegFieldHandlerTest extends TestCase
@@ -23,22 +24,22 @@ class ParticipantVegFieldHandlerTest extends TestCase
public function testGetFieldName(): void
{
$this->assertEquals('veg', $this->handler->getFieldName());
self::assertEquals('veg', $this->handler->getFieldName());
}
public function testGetDependencies(): void
{
$dependencies = $this->handler->getDependencies();
$this->assertEquals(['dateOfBirth'], $dependencies);
self::assertEquals(['dateOfBirth'], $dependencies);
}
public function testShouldProcessAlwaysReturnsTrue(): void
{
// Should always process to handle deselection cases
$this->assertTrue($this->handler->shouldProcess([], BookingDto::MODE_CREATE, 0));
$this->assertTrue($this->handler->shouldProcess([], BookingDto::MODE_EDIT, 0));
$this->assertTrue($this->handler->shouldProcess(['veg' => '123'], BookingDto::MODE_CREATE, 0));
self::assertTrue($this->handler->shouldProcess([], BookingDto::MODE_CREATE, 0));
self::assertTrue($this->handler->shouldProcess([], BookingDto::MODE_EDIT, 0));
self::assertTrue($this->handler->shouldProcess(['veg' => '123'], BookingDto::MODE_CREATE, 0));
}
public function testProcessFieldDoesNothingWhenNoParticipant(): void
@@ -63,7 +64,7 @@ class ParticipantVegFieldHandlerTest extends TestCase
$this->handler->processField(['veg' => null], $bookingDto, 0);
$this->assertNull($participant->veg);
self::assertNull($participant->veg);
}
public function testProcessFieldClearsVegWhenEmptyStringSelection(): void
@@ -77,7 +78,7 @@ class ParticipantVegFieldHandlerTest extends TestCase
$this->handler->processField(['veg' => ''], $bookingDto, 0);
$this->assertNull($participant->veg);
self::assertNull($participant->veg);
}
public function testProcessFieldClearsVegWhenMissingFromData(): void
@@ -91,7 +92,7 @@ class ParticipantVegFieldHandlerTest extends TestCase
$this->handler->processField([], $bookingDto, 0);
$this->assertNull($participant->veg);
self::assertNull($participant->veg);
}
public function testProcessFieldClearsVegWhenNotFoundInAvailableServices(): void
@@ -105,7 +106,7 @@ class ParticipantVegFieldHandlerTest extends TestCase
$this->handler->processField(['veg' => '123'], $bookingDto, 0);
$this->assertNull($participant->veg);
self::assertNull($participant->veg);
}
public function testProcessFieldSetsVegWhenAvailable(): void
@@ -119,7 +120,7 @@ class ParticipantVegFieldHandlerTest extends TestCase
$this->handler->processField(['veg' => '123'], $bookingDto, 0);
$this->assertSame($vegService, $participant->veg);
self::assertSame($vegService, $participant->veg);
}
public function testProcessFieldWorksWithStringAndIntegerIds(): void
@@ -133,7 +134,7 @@ class ParticipantVegFieldHandlerTest extends TestCase
$this->handler->processField(['veg' => '123'], $bookingDto, 0); // String selection
$this->assertSame($vegService, $participant->veg);
self::assertSame($vegService, $participant->veg);
}
public function testProcessFieldHandlesEmptyServicesArray(): void
@@ -146,7 +147,7 @@ class ParticipantVegFieldHandlerTest extends TestCase
$this->handler->processField(['veg' => '123'], $bookingDto, 0);
$this->assertNull($participant->veg);
self::assertNull($participant->veg);
}
public function testProcessFieldSelectsFromMultipleVegOptions(): void
@@ -161,7 +162,7 @@ class ParticipantVegFieldHandlerTest extends TestCase
$this->handler->processField(['veg' => '2'], $bookingDto, 0);
$this->assertSame($vegan, $participant->veg);
self::assertSame($vegan, $participant->veg);
}
public function testGetFieldStateModificationsReturnsEmptyArray(): void
@@ -170,16 +171,16 @@ class ParticipantVegFieldHandlerTest extends TestCase
$result = $this->handler->getFieldStateModifications([], $bookingDto, 0);
$this->assertIsArray($result);
$this->assertEmpty($result);
self::assertIsArray($result);
self::assertEmpty($result);
}
public function testGetAffectedFieldNamesReturnsEmptyArray(): void
{
$result = $this->handler->getAffectedFieldNames();
$this->assertIsArray($result);
$this->assertEmpty($result);
self::assertIsArray($result);
self::assertEmpty($result);
}
private function createService(int $id, string $label = 'Test Service'): Service
@@ -192,6 +193,11 @@ class ParticipantVegFieldHandlerTest extends TestCase
return $service;
}
/**
* @param array<int, Service> $vegServices
*
* @return Travel&MockObject
*/
private function createMockTravel(array $vegServices): Travel
{
$travel = $this->createMock(Travel::class);
@@ -202,6 +208,9 @@ class ParticipantVegFieldHandlerTest extends TestCase
return $travel;
}
/**
* @return BookingDto&MockObject
*/
private function createMockBookingDto(?Travel $travel = null): BookingDto
{
$bookingDto = $this->createMock(BookingDto::class);