chore: cleanup
This commit is contained in:
1 parent
400407358d
commit
36ef54d541
6 files changed
+62
-231
No files matched your search
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service\Abstract;
|
||||
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Contract\ParticipantFieldHandlerInterface;
|
||||
|
||||
@@ -190,19 +191,22 @@ abstract class AbstractParticipantFieldHandler implements ParticipantFieldHandle
|
||||
* items and returning the matching object. Used by handlers that need to
|
||||
* validate service, pickup, or other selections against available options.
|
||||
*
|
||||
* Normalizes the input ID to integer before comparison since Service, Pickup,
|
||||
* and Room models all use integer IDs.
|
||||
*
|
||||
* @param mixed $selectedId The submitted ID to find (string or int)
|
||||
* @param object[] $items Array of objects with an `id` property
|
||||
* @param object[] $items Array of objects with an `id` property (must be int)
|
||||
*
|
||||
* @return object|null The matching item, or null if not found or invalid ID
|
||||
*/
|
||||
protected function findItemById(mixed $selectedId, array $items): ?object
|
||||
{
|
||||
if (null === $selectedId || (false === is_string($selectedId) && false === is_int($selectedId))) {
|
||||
$id = $this->normalizeIntValue($selectedId);
|
||||
|
||||
if (null === $id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$id = (int) $selectedId;
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item->id === $id) {
|
||||
return $item;
|
||||
@@ -211,4 +215,58 @@ abstract class AbstractParticipantFieldHandler implements ParticipantFieldHandle
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a Service in available services by matching the selected value.
|
||||
*
|
||||
* Handles various input types that may come from form submissions:
|
||||
* - Service object: matches by object identity or ID
|
||||
* - Integer/numeric string: matches by ID
|
||||
*
|
||||
* @param mixed $selectedService The selected service (Service object, int, or numeric string)
|
||||
* @param Service[] $availableServices Array of available Service objects
|
||||
*
|
||||
* @return Service|null The matching Service, or null if not found
|
||||
*/
|
||||
protected function findServiceInAvailableServices(mixed $selectedService, array $availableServices): ?Service
|
||||
{
|
||||
foreach ($availableServices as $availableService) {
|
||||
if ($this->servicesMatch($selectedService, $availableService)) {
|
||||
return $availableService;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a selected service matches an available service.
|
||||
*
|
||||
* Compares services by object identity first, then by ID. Handles Service objects,
|
||||
* integers, and numeric strings from form submissions.
|
||||
*
|
||||
* @param mixed $selectedService The selected service to compare
|
||||
* @param Service $availableService The available service to compare against
|
||||
*
|
||||
* @return bool True if the services match, false otherwise
|
||||
*/
|
||||
protected function servicesMatch(mixed $selectedService, Service $availableService): bool
|
||||
{
|
||||
// Direct object comparison
|
||||
if ($selectedService === $availableService) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// ID comparison for Service objects
|
||||
if ($selectedService instanceof Service) {
|
||||
return $selectedService->id === $availableService->id;
|
||||
}
|
||||
|
||||
// ID comparison for numeric values (int or numeric string from form)
|
||||
if (is_numeric($selectedService)) {
|
||||
return (int) $selectedService === $availableService->id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user