From d152efe084aa4d3455d2ae9c928128ec4d560deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 9 Sep 2024 14:58:19 +0200 Subject: [PATCH] Refactor imports and remove redundant type strings This commit refactors the usage of \DateTimeImmutable to ensure consistent namespacing and removes unnecessary string type declarations from constants in CancelStaleWorkflowCronJob. These changes improve code readability and maintainability. --- .../Workflow/CancelStaleWorkflowCronJob.php | 6 +++--- .../Workflow/CancelStaleWorkflowCronJobTest.php | 17 +++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowCronJob.php b/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowCronJob.php index 786bae3c9..767af2c5c 100644 --- a/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowCronJob.php +++ b/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowCronJob.php @@ -20,11 +20,11 @@ use Symfony\Component\Messenger\MessageBusInterface; class CancelStaleWorkflowCronJob implements CronJobInterface { - public const string KEY = 'remove-stale-workflow'; + public const KEY = 'remove-stale-workflow'; - public const string KEEP_INTERVAL = 'P90D'; + public const KEEP_INTERVAL = 'P90D'; - private const string LAST_CANCELED_WORKFLOW = 'last-canceled-workflow-id'; + private const LAST_CANCELED_WORKFLOW = 'last-canceled-workflow-id'; public function __construct( private readonly EntityWorkflowRepository $workflowRepository, diff --git a/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php b/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php index f433e8b48..8e06735f6 100644 --- a/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php @@ -16,9 +16,6 @@ use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository; use Chill\MainBundle\Service\Workflow\CancelStaleWorkflow; use Chill\MainBundle\Service\Workflow\CancelStaleWorkflowCronJob; use Chill\MainBundle\Service\Workflow\CancelStaleWorkflowMessage; -use DateInvalidTimeZoneException; -use DateMalformedStringException; -use DateTimeImmutable; use Doctrine\DBAL\Connection; use PHPUnit\Framework\MockObject\Exception; use Psr\Log\LoggerInterface; @@ -47,7 +44,7 @@ class CancelStaleWorkflowCronJobTest extends KernelTestCase */ public function testCanRun(?CronJobExecution $cronJobExecution, bool $expected): void { - $clock = new MockClock(new DateTimeImmutable('2024-01-01 00:00:00', new \DateTimeZone('+00:00'))); + $clock = new MockClock(new \DateTimeImmutable('2024-01-01 00:00:00', new \DateTimeZone('+00:00'))); $logger = $this->createMock(LoggerInterface::class); $cronJob = new CancelStaleWorkflowCronJob($this->createMock(EntityWorkflowRepository::class), $clock, $this->buildMessageBus(), $logger); @@ -56,13 +53,13 @@ class CancelStaleWorkflowCronJobTest extends KernelTestCase } /** - * @throws DateMalformedStringException - * @throws DateInvalidTimeZoneException + * @throws \DateMalformedStringException + * @throws \DateInvalidTimeZoneException * @throws \Exception|Exception */ public function testRun(): void { - $clock = new MockClock((new DateTimeImmutable('now', new \DateTimeZone('+00:00')))->add(new \DateInterval('P120D'))); + $clock = new MockClock((new \DateTimeImmutable('now', new \DateTimeZone('+00:00')))->add(new \DateInterval('P120D'))); $workflowRepository = $this->createMock(EntityWorkflowRepository::class); $logger = $this->createMock(LoggerInterface::class); @@ -84,17 +81,17 @@ class CancelStaleWorkflowCronJobTest extends KernelTestCase public static function buildTestCanRunData(): iterable { yield [ - (new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new DateTimeImmutable('2023-12-31 00:00:00', new \DateTimeZone('+00:00'))), + (new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new \DateTimeImmutable('2023-12-31 00:00:00', new \DateTimeZone('+00:00'))), true, ]; yield [ - (new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new DateTimeImmutable('2023-12-30 23:59:59', new \DateTimeZone('+00:00'))), + (new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new \DateTimeImmutable('2023-12-30 23:59:59', new \DateTimeZone('+00:00'))), true, ]; yield [ - (new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new DateTimeImmutable('2023-12-31 00:00:01', new \DateTimeZone('+00:00'))), + (new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new \DateTimeImmutable('2023-12-31 00:00:01', new \DateTimeZone('+00:00'))), false, ]; }