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

+5 -2
View File
@@ -50,8 +50,11 @@ class BpnFetchTravelCommand extends Command
$io = new SymfonyStyle($input, $output);
$travelId = (int) $input->getArgument('travel-id');
$filename = $input->getOption('filename') ?? sprintf('Ziel_%d.xml', $travelId);
$dryRun = $input->getOption('dry-run');
$filenameOption = $input->getOption('filename');
$filename = is_string($filenameOption) && '' !== $filenameOption
? $filenameOption
: sprintf('Ziel_%d.xml', $travelId);
$dryRun = true === $input->getOption('dry-run');
$io->text(sprintf('Fetching travel data for product ID %d...', $travelId));
+14 -4
View File
@@ -39,7 +39,14 @@ class BpnReplayCommand extends Command
{
$io = new SymfonyStyle($input, $output);
$filePath = $input->getArgument('file');
$filePathArgument = $input->getArgument('file');
if (!is_string($filePathArgument) || '' === $filePathArgument) {
$io->error('Invalid file path argument.');
return Command::FAILURE;
}
$filePath = $filePathArgument;
if (false === file_exists($filePath)) {
$io->error(sprintf('File not found: %s', $filePath));
@@ -84,8 +91,9 @@ class BpnReplayCommand extends Command
return Command::FAILURE;
}
$outputFile = $input->getOption('output');
if (null !== $outputFile) {
$outputFileOption = $input->getOption('output');
if (is_string($outputFileOption) && '' !== $outputFileOption) {
$outputFile = $outputFileOption;
if (false === file_put_contents($outputFile, $response)) {
$io->error(sprintf('Failed to write response to: %s', $outputFile));
@@ -139,6 +147,8 @@ class BpnReplayCommand extends Command
return $xml;
}
return $doc->saveXML() ?: $xml;
$formattedXml = $doc->saveXML();
return false === $formattedXml ? $xml : $formattedXml;
}
}
+2 -2
View File
@@ -65,8 +65,8 @@ class BpnXmlSyncCommand extends Command
return Command::SUCCESS;
}
$force = $input->getOption('force');
$dryRun = $input->getOption('dry-run');
$force = true === $input->getOption('force');
$dryRun = true === $input->getOption('dry-run');
$remoteInfo = $this->readRemoteInfo();
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace App\Command;
@@ -41,7 +41,7 @@ class DraftBackfillBookingNumberCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$dryRun = $input->getOption('dry-run');
$dryRun = true === $input->getOption('dry-run');
$drafts = $this->draftRepository->findBy(['bookingNumber' => null]);
@@ -80,7 +80,7 @@ class DraftBackfillBookingNumberCommand extends Command
continue;
}
if ($dryRun) {
if (true === $dryRun) {
$io->text(sprintf(
'[DRY RUN] Would set booking number %d for draft %d (bookingId %d)',
$bookingNumber,
@@ -108,7 +108,7 @@ class DraftBackfillBookingNumberCommand extends Command
]
);
if ($dryRun) {
if (true === $dryRun) {
$io->note('Dry run - no changes were made.');
} else {
$io->success(sprintf('Updated %d draft(s).', $updated));
+2 -2
View File
@@ -38,9 +38,9 @@ class DraftCleanupCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$dryRun = $input->getOption('dry-run');
$dryRun = true === $input->getOption('dry-run');
if ($dryRun) {
if (true === $dryRun) {
$expiredDrafts = $this->draftRepository->createQueryBuilder('d')
->where('d.travelDate < :today')
->setParameter('today', new \DateTimeImmutable('today'))
+9 -6
View File
@@ -38,9 +38,12 @@ class DraftInspectCommand extends Command
{
$io = new SymfonyStyle($input, $output);
$days = $input->getOption('days');
$bookingId = $input->getOption('booking-id');
$shouldDelete = $input->getOption('delete');
$daysOption = $input->getOption('days');
$bookingIdOption = $input->getOption('booking-id');
$shouldDelete = true === $input->getOption('delete');
$days = is_numeric($daysOption) ? (int) $daysOption : null;
$bookingId = is_numeric($bookingIdOption) ? (int) $bookingIdOption : null;
$qb = $this->draftRepository->createQueryBuilder('d')
->join('d.user', 'u')
@@ -48,14 +51,14 @@ class DraftInspectCommand extends Command
->orderBy('d.updatedAt', 'DESC');
if (null !== $days) {
$cutoffDate = new \DateTimeImmutable(sprintf('-%d days', (int) $days));
$cutoffDate = new \DateTimeImmutable(sprintf('-%d days', $days));
$qb->andWhere('d.updatedAt < :cutoff')
->setParameter('cutoff', $cutoffDate);
}
if (null !== $bookingId) {
$qb->andWhere('d.bookingId = :bookingId')
->setParameter('bookingId', (int) $bookingId);
->setParameter('bookingId', $bookingId);
}
$drafts = $qb->getQuery()->getResult();
@@ -97,7 +100,7 @@ class DraftInspectCommand extends Command
'Drafts are preserved when: user cancels, API rejects submission, or user simply leaves',
]);
if ($shouldDelete) {
if (true === $shouldDelete) {
if (false === $io->confirm(sprintf('Are you sure you want to delete %d draft(s)?', \count($drafts)), false)) {
$io->warning('Deletion cancelled.');
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace App\Command;