chore: code cleanup

This commit is contained in:
Björn Fromme
2026-03-16 12:01:09 +01:00
parent e5781fbabc
commit fd81079247
2 changed files with 21 additions and 29 deletions
+13 -15
View File
@@ -10,6 +10,7 @@ use App\BusProNet\Model\Booking;
use App\BusProNet\Model\Notification;
use App\Entity\User;
use App\Form\Model\BookingDto;
use App\Security\Crypt;
use Psr\Cache\InvalidArgumentException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Cache\ItemInterface;
@@ -34,6 +35,7 @@ class BookingEditDataLoaderService
private readonly BookingFingerprintService $fingerprintService,
private readonly TravelDataService $travelDataService,
private readonly BookingEditDraftService $draftService,
private readonly Crypt $crypt,
private readonly TagAwareCacheInterface $bpnCache,
) {
}
@@ -58,13 +60,11 @@ class BookingEditDataLoaderService
*
* @param Request $request The HTTP request
* @param int $bookingId The booking ID to load
* @param string $email User email for API authentication
* @param string $password User password for API authentication
* @param User $user The authenticated user (for draft lookup)
* @param User $user The authenticated user
*
* @return BookingDto|null The loaded booking DTO, or null if loading failed
*/
public function loadFormData(Request $request, int $bookingId, string $email, string $password, User $user): ?BookingDto
public function loadFormData(Request $request, int $bookingId, User $user): ?BookingDto
{
$this->draftWasRestored = false;
@@ -77,7 +77,7 @@ class BookingEditDataLoaderService
}
if (null === $formData) {
return $this->initializeFromApi($request, $bookingId, $email, $password, $user);
return $this->initializeFromApi($request, $bookingId, $user);
}
// Refresh availability data
@@ -95,15 +95,13 @@ class BookingEditDataLoaderService
*
* @param Request $request The HTTP request
* @param int $bookingId The booking ID to load
* @param string $email User email for API authentication
* @param string $password User password for API authentication
* @param User $user The authenticated user (for draft lookup)
* @param User $user The authenticated user
*
* @return BookingDto|null The loaded booking DTO, or null if loading failed
*/
public function initializeFromApi(Request $request, int $bookingId, string $email, string $password, User $user): ?BookingDto
public function initializeFromApi(Request $request, int $bookingId, User $user): ?BookingDto
{
$bookingData = $this->fetchBookingData($email, $password, $bookingId, $user);
$bookingData = $this->fetchBookingData($bookingId, $user);
if (null === $bookingData || $bookingData instanceof Notification) {
return null;
@@ -151,17 +149,17 @@ class BookingEditDataLoaderService
* Cache entries are tagged with the user ID to allow bulk invalidation
* when the user updates their personal data.
*
* @param string $email User email for API authentication
* @param string $password User password for API authentication
* @param int $bookingId The booking ID to fetch
* @param User $user The user for cache tagging
* @param int $bookingId The booking ID to fetch
* @param User $user The authenticated user
*
* @return Booking|Notification|null The booking data, notification on error, or null on cache failure
*/
public function fetchBookingData(string $email, string $password, int $bookingId, User $user): Booking|Notification|null
public function fetchBookingData(int $bookingId, User $user): Booking|Notification|null
{
$cacheKey = sprintf('bpn_booking_%d', $bookingId);
$userTag = self::CACHE_TAG_USER_PREFIX.$user->getId();
$email = $user->getEmail();
$password = $this->crypt->decrypt($user->getPassword());
try {
return $this->bpnCache->get($cacheKey, function (ItemInterface $item) use ($email, $password, $bookingId, $userTag) {