apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -20,11 +20,12 @@ interface CronJobInterface
public function getKey(): string;
/**
* Execute the cronjob
* Execute the cronjob.
*
* If data is returned, this data is passed as argument on the next execution
*
* @param array $lastExecutionData the data which was returned from the previous execution
*
* @return array|null optionally return an array with the same data than the previous execution
*/
public function run(array $lastExecutionData): null|array;

View File

@@ -13,12 +13,10 @@ namespace Chill\MainBundle\Cron;
use Chill\MainBundle\Entity\CronJobExecution;
use Chill\MainBundle\Repository\CronJobExecutionRepositoryInterface;
use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Psr\Log\LoggerInterface;
use function array_key_exists;
/**
* Manage cronjob and execute them.
@@ -43,11 +41,11 @@ final readonly class CronManager implements CronManagerInterface
{
private const LOG_PREFIX = '[cron manager] ';
private const UPDATE_AFTER_EXEC = 'UPDATE ' . CronJobExecution::class . ' cr SET cr.lastEnd = :now, cr.lastStatus = :status WHERE cr.key = :key';
private const UPDATE_AFTER_EXEC = 'UPDATE '.CronJobExecution::class.' cr SET cr.lastEnd = :now, cr.lastStatus = :status WHERE cr.key = :key';
private const UPDATE_BEFORE_EXEC = 'UPDATE ' . CronJobExecution::class . ' cr SET cr.lastStart = :now WHERE cr.key = :key';
private const UPDATE_BEFORE_EXEC = 'UPDATE '.CronJobExecution::class.' cr SET cr.lastStart = :now WHERE cr.key = :key';
private const UPDATE_LAST_EXECUTION_DATA = 'UPDATE ' . CronJobExecution::class . ' cr SET cr.lastExecutionData = :data WHERE cr.key = :key';
private const UPDATE_LAST_EXECUTION_DATA = 'UPDATE '.CronJobExecution::class.' cr SET cr.lastExecutionData = :data WHERE cr.key = :key';
/**
* @param CronJobInterface[] $jobs
@@ -59,7 +57,7 @@ final readonly class CronManager implements CronManagerInterface
private LoggerInterface $logger
) {}
public function run(?string $forceJob = null): void
public function run(string $forceJob = null): void
{
if (null !== $forceJob) {
$this->runForce($forceJob);
@@ -71,13 +69,13 @@ final readonly class CronManager implements CronManagerInterface
foreach ($orderedJobs as $job) {
if ($job->canRun($lasts[$job->getKey()] ?? null)) {
if (array_key_exists($job->getKey(), $lasts)) {
if (\array_key_exists($job->getKey(), $lasts)) {
$executionData = $lasts[$job->getKey()]->getLastExecutionData();
$this->entityManager
->createQuery(self::UPDATE_BEFORE_EXEC)
->setParameters([
'now' => new DateTimeImmutable('now'),
'now' => new \DateTimeImmutable('now'),
'key' => $job->getKey(),
])
->execute();
@@ -100,7 +98,7 @@ final readonly class CronManager implements CronManagerInterface
$this->entityManager
->createQuery(self::UPDATE_AFTER_EXEC)
->setParameters([
'now' => new DateTimeImmutable('now'),
'now' => new \DateTimeImmutable('now'),
'status' => CronJobExecution::SUCCESS,
'key' => $job->getKey(),
])
@@ -117,12 +115,12 @@ final readonly class CronManager implements CronManagerInterface
$this->logger->info(sprintf('%sSuccessfully run job', self::LOG_PREFIX), ['job' => $job->getKey()]);
return;
} catch (Exception) {
} catch (\Exception) {
$this->logger->error(sprintf('%sRunning job failed', self::LOG_PREFIX), ['job' => $job->getKey()]);
$this->entityManager
->createQuery(self::UPDATE_AFTER_EXEC)
->setParameters([
'now' => new DateTimeImmutable('now'),
'now' => new \DateTimeImmutable('now'),
'status' => CronJobExecution::FAILURE,
'key' => $job->getKey(),
])
@@ -152,16 +150,16 @@ final readonly class CronManager implements CronManagerInterface
$orderedJobs,
static function (CronJobInterface $a, CronJobInterface $b) use ($lasts): int {
if (
(!array_key_exists($a->getKey(), $lasts) && !array_key_exists($b->getKey(), $lasts))
!\array_key_exists($a->getKey(), $lasts) && !\array_key_exists($b->getKey(), $lasts)
) {
return 0;
}
if (!array_key_exists($a->getKey(), $lasts) && array_key_exists($b->getKey(), $lasts)) {
if (!\array_key_exists($a->getKey(), $lasts) && \array_key_exists($b->getKey(), $lasts)) {
return -1;
}
if (!array_key_exists($b->getKey(), $lasts) && array_key_exists($a->getKey(), $lasts)) {
if (!\array_key_exists($b->getKey(), $lasts) && \array_key_exists($a->getKey(), $lasts)) {
return 1;
}

View File

@@ -16,5 +16,5 @@ interface CronManagerInterface
/**
* Execute one job, with a given priority, or the given job (identified by his key).
*/
public function run(?string $forceJob = null): void;
public function run(string $forceJob = null): void;
}