48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service;
|
|
|
|
use App\BusProNet\Model\PersonalData;
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
|
|
/**
|
|
* Validates profile completeness for booking requirements.
|
|
*
|
|
* Checks whether a user's personal data contains all required fields needed to create
|
|
* or edit bookings using Symfony's validation system with the 'personal_data' group.
|
|
* Required fields include name, gender, date of birth, nationality, contact information,
|
|
* and full address data.
|
|
*/
|
|
class ProfileCompletenessChecker
|
|
{
|
|
private const VALIDATION_GROUP = 'personal_data';
|
|
|
|
public function __construct(
|
|
private readonly ValidatorInterface $validator,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Checks if the personal data contains all required fields for booking operations.
|
|
*
|
|
* Validates against the 'personal_data' group which includes:
|
|
* - firstName and name (personal identification)
|
|
* - gender and dateOfBirth (personal attributes)
|
|
* - nationality (booking form requirement)
|
|
* - email and mobile (communication)
|
|
* - street, postCode, city, country (applicant address)
|
|
*
|
|
* @param PersonalData $personalData The personal data to validate
|
|
*
|
|
* @return bool True if all required fields are present and valid, false otherwise
|
|
*/
|
|
public function isComplete(PersonalData $personalData): bool
|
|
{
|
|
$violations = $this->validator->validate($personalData, null, [self::VALIDATION_GROUP]);
|
|
|
|
return 0 === $violations->count();
|
|
}
|
|
}
|