chore: cleanup
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,63 +184,4 @@ class ParticipantAdditionalServicesFieldHandler extends AbstractParticipantField
|
||||
// Validate service against participant's age
|
||||
return $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a selected service in the list of available services.
|
||||
*
|
||||
* This method handles different representations of services (objects, IDs, etc.)
|
||||
* and locates the corresponding service in the available services array.
|
||||
*
|
||||
* @param mixed $selectedService The selected service to find
|
||||
* @param array $availableServices Array of available Service objects
|
||||
*
|
||||
* @return Service|null The found service or null if not found
|
||||
*/
|
||||
private function findServiceInAvailableServices(mixed $selectedService, array $availableServices): ?Service
|
||||
{
|
||||
foreach ($availableServices as $availableService) {
|
||||
// Handle different comparison scenarios
|
||||
if ($this->servicesMatch($selectedService, $availableService)) {
|
||||
return $availableService;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a selected service matches an available service.
|
||||
*
|
||||
* This method handles various service representation formats that might
|
||||
* come from form submissions (objects, IDs, arrays, etc.).
|
||||
*
|
||||
* @param mixed $selectedService The selected service from form data
|
||||
* @param Service $availableService The available service to compare against
|
||||
*
|
||||
* @return bool True if the services match, false otherwise
|
||||
*/
|
||||
private 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
|
||||
if (is_numeric($selectedService)) {
|
||||
return (int) $selectedService === $availableService->id;
|
||||
}
|
||||
|
||||
// String ID comparison
|
||||
if (is_string($selectedService)) {
|
||||
return $selectedService === (string) $availableService->id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,36 +110,4 @@ class ParticipantBoardFieldHandler extends AbstractParticipantFieldHandler
|
||||
|
||||
return $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex);
|
||||
}
|
||||
|
||||
private function findServiceInAvailableServices(mixed $selectedService, array $availableServices): ?Service
|
||||
{
|
||||
foreach ($availableServices as $availableService) {
|
||||
if ($this->servicesMatch($selectedService, $availableService)) {
|
||||
return $availableService;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function servicesMatch(mixed $selectedService, Service $availableService): bool
|
||||
{
|
||||
if ($selectedService === $availableService) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($selectedService instanceof Service) {
|
||||
return $selectedService->id === $availableService->id;
|
||||
}
|
||||
|
||||
if (is_numeric($selectedService)) {
|
||||
return (int) $selectedService === $availableService->id;
|
||||
}
|
||||
|
||||
if (is_string($selectedService)) {
|
||||
return $selectedService === (string) $availableService->id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,56 +170,4 @@ class ParticipantCoursesFieldHandler extends AbstractParticipantFieldHandler
|
||||
// Validate service against participant's age
|
||||
return $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a selected course in the list of available courses.
|
||||
*
|
||||
* @param mixed $selectedService The selected course to find
|
||||
* @param array $availableServices Array of available Service objects
|
||||
*
|
||||
* @return Service|null The found service or null if not found
|
||||
*/
|
||||
private function findServiceInAvailableServices(mixed $selectedService, array $availableServices): ?Service
|
||||
{
|
||||
foreach ($availableServices as $availableService) {
|
||||
if ($this->servicesMatch($selectedService, $availableService)) {
|
||||
return $availableService;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a selected course matches an available course.
|
||||
*
|
||||
* @param mixed $selectedService The selected course from form data
|
||||
* @param Service $availableService The available course to compare against
|
||||
*
|
||||
* @return bool True if the courses match, false otherwise
|
||||
*/
|
||||
private 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
|
||||
if (is_numeric($selectedService)) {
|
||||
return (int) $selectedService === $availableService->id;
|
||||
}
|
||||
|
||||
// String ID comparison
|
||||
if (is_string($selectedService)) {
|
||||
return $selectedService === (string) $availableService->id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,38 +147,6 @@ class ParticipantRentalsFieldHandler extends AbstractParticipantFieldHandler
|
||||
return $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex);
|
||||
}
|
||||
|
||||
private function findServiceInAvailableServices(mixed $selectedService, array $availableServices): ?Service
|
||||
{
|
||||
foreach ($availableServices as $availableService) {
|
||||
if ($this->servicesMatch($selectedService, $availableService)) {
|
||||
return $availableService;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function servicesMatch(mixed $selectedService, Service $availableService): bool
|
||||
{
|
||||
if ($selectedService === $availableService) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($selectedService instanceof Service) {
|
||||
return $selectedService->id === $availableService->id;
|
||||
}
|
||||
|
||||
if (is_numeric($selectedService)) {
|
||||
return (int) $selectedService === $availableService->id;
|
||||
}
|
||||
|
||||
if (is_string($selectedService)) {
|
||||
return $selectedService === (string) $availableService->id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters rentals to only include those matching the skipass duration.
|
||||
*
|
||||
|
||||
@@ -151,56 +151,4 @@ class ParticipantSkiPassFieldHandler extends AbstractParticipantFieldHandler
|
||||
|
||||
return true; // Service passed both age and date validation
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a selected skipass in the list of available skipasses.
|
||||
*
|
||||
* @param mixed $selectedService The selected skipass to find
|
||||
* @param array $availableServices Array of available Service objects
|
||||
*
|
||||
* @return Service|null The found service or null if not found
|
||||
*/
|
||||
private function findServiceInAvailableServices(mixed $selectedService, array $availableServices): ?Service
|
||||
{
|
||||
foreach ($availableServices as $availableService) {
|
||||
if ($this->servicesMatch($selectedService, $availableService)) {
|
||||
return $availableService;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a selected skipass matches an available skipass.
|
||||
*
|
||||
* @param mixed $selectedService The selected skipass from form data
|
||||
* @param Service $availableService The available skipass to compare against
|
||||
*
|
||||
* @return bool True if the skipasses match, false otherwise
|
||||
*/
|
||||
private 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
|
||||
if (is_numeric($selectedService)) {
|
||||
return (int) $selectedService === $availableService->id;
|
||||
}
|
||||
|
||||
// String ID comparison
|
||||
if (is_string($selectedService)) {
|
||||
return $selectedService === (string) $availableService->id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user