Olivier Massot 1 gadu atpakaļ
vecāks
revīzija
3d23063d0a

+ 18 - 20
src/Commands/CronCommand.php

@@ -17,7 +17,6 @@ use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Contracts\Service\Attribute\Required;
-use Throwable;
 
 /**
  * CLI Command to run the cron-jobs.
@@ -55,7 +54,11 @@ class CronCommand extends Command
     /** @noinspection PhpUnused */
     #[Required]
     /** @see https://symfony.com/doc/current/logging/channels_handlers.html#how-to-autowire-logger-channels */
-    public function setLoggerInterface(LoggerInterface $cronLogger): void { $this->logger = $cronLogger; }
+    public function setLoggerInterface(LoggerInterface $cronLogger): void
+    {
+        $this->logger = $cronLogger;
+    }
+
     /** @noinspection PhpUnused */
     #[Required]
     public function setCronjobIterator(CronjobIterator $cronjobIterator): void
@@ -144,7 +147,7 @@ class CronCommand extends Command
 
         foreach ($jobs as $job) {
             $this->logger->info(
-                'CronCommand will execute `' . $job->name() . '`' . ($preview ? ' [PREVIEW MODE]' : '')
+                'CronCommand will execute `'.$job->name().'`'.($preview ? ' [PREVIEW MODE]' : '')
             );
 
             $results[] = $this->runJob($job, $preview);
@@ -209,15 +212,14 @@ class CronCommand extends Command
 
             $t1 = microtime(true);
 
-            $msg = "Job has been successfully executed (" . round($t1 - $t0, 2) . " sec.)" . ($preview ? ' [PREVIEW MODE]' : '');
+            $msg = 'Job has been successfully executed ('.round($t1 - $t0, 2).' sec.)'.($preview ? ' [PREVIEW MODE]' : '');
             $this->output->writeln($formatter->formatSection($job->name(), $msg));
-            $this->logger->info($job->name() . ' - ' . $msg);
-
-        } catch (Throwable $e) {
+            $this->logger->info($job->name().' - '.$msg);
+        } catch (\Throwable $e) {
             $this->logger->critical($e);
-            $this->output->write("An error happened while running the process : " . $e);
-            return Command::FAILURE;
+            $this->output->write('An error happened while running the process : '.$e);
 
+            return Command::FAILURE;
         } finally {
             $this->resetLoggerFormatter();
         }
@@ -226,18 +228,15 @@ class CronCommand extends Command
     }
 
     /**
-     * Modify the RotatingFile logger line format to match the display the current job's name (if any)
-     *
-     * @param string|null $jobName
-     * @return void
+     * Modify the RotatingFile logger line format to match the display the current job's name (if any).
      */
-    protected function configureLoggerFormatter(string | null $jobName = null): void {
-        /** @noinspection PhpPossiblePolymorphicInvocationInspection @phpstan-ignore-next-line */
+    protected function configureLoggerFormatter(?string $jobName = null): void
+    {
+        /* @noinspection PhpPossiblePolymorphicInvocationInspection @phpstan-ignore-next-line */
         foreach ($this->logger->getHandlers() as $handler) {
             if ($handler instanceof RotatingFileHandler) {
-
-                $format = "[%datetime%] " .
-                          ($jobName !== null ? "[" . $jobName . "] " : "") .
+                $format = '[%datetime%] '.
+                          ($jobName !== null ? '['.$jobName.'] ' : '').
                           "%channel%.%level_name%: %message% %context% %extra%\n";
 
                 $handler->setFormatter(new LineFormatter($format, 'Y-m-d H:i:s.v'));
@@ -246,8 +245,7 @@ class CronCommand extends Command
     }
 
     /**
-     * Alias for `$this->configureLoggerFormatter(null)`
-     * @return void
+     * Alias for `$this->configureLoggerFormatter(null)`.
      */
     protected function resetLoggerFormatter(): void
     {

+ 0 - 1
src/Service/Cron/Job/CleanDb.php

@@ -3,7 +3,6 @@
 namespace App\Service\Cron\Job;
 
 use App\Service\Cron\BaseCronJob;
-use App\Service\Cron\CronjobInterface;
 use App\Service\Utils\DatesUtils;
 use Doctrine\DBAL\Connection;
 use Doctrine\DBAL\DBALException;

+ 0 - 1
src/Service/Cron/Job/CleanTempFiles.php

@@ -7,7 +7,6 @@ use App\Enum\Core\FileHostEnum;
 use App\Enum\Core\FileStatusEnum;
 use App\Repository\Core\FileRepository;
 use App\Service\Cron\BaseCronJob;
-use App\Service\Cron\CronjobInterface;
 use App\Service\File\Storage\LocalStorage;
 use App\Service\Utils\DatesUtils;
 use Doctrine\DBAL\Connection;

+ 0 - 1
src/Service/Cron/Job/DolibarrSync.php

@@ -3,7 +3,6 @@
 namespace App\Service\Cron\Job;
 
 use App\Service\Cron\BaseCronJob;
-use App\Service\Cron\CronjobInterface;
 use App\Service\Dolibarr\DolibarrSyncService;
 use JetBrains\PhpStorm\Pure;
 

+ 3 - 4
src/Service/Dolibarr/DolibarrSyncService.php

@@ -334,7 +334,7 @@ class DolibarrSyncService
             // Update Billing service contact (if existing)
             foreach ($dolibarrSocietyContacts as $contactData) {
                 if (
-                    'service facturation' === strtolower($contactData['lastname'])
+                    strtolower($contactData['lastname']) === 'service facturation'
                     && empty($contactData['name'])
                     && empty($contactData['array_options']['options_2iopen_person_id'])
                 ) {
@@ -755,9 +755,8 @@ class DolibarrSyncService
     /**
      * Returns the number of accesses possessing at least one of the missions.
      *
-     * @param array<string> $missions A list of missions
-     * @param array<string, array<string>> $members An organization members as returned by getActiveMembersIndex: [$accessID => [$missions...]]
-     * @return int
+     * @param array<string>                $missions A list of missions
+     * @param array<string, array<string>> $members  An organization members as returned by getActiveMembersIndex: [$accessID => [$missions...]]
      */
     protected function countWithMission(array $missions, array $members): int
     {

+ 19 - 5
tests/Unit/Service/Cron/BaseCronJobTest.php

@@ -9,11 +9,25 @@ use App\Service\Cron\UI\SilentUI;
 use PHPUnit\Framework\TestCase;
 use Psr\Log\LoggerInterface;
 
-class TestableBaseCronJob extends BaseCronJob {
-    public function getUI(): CronUIInterface { return $this->ui; }
-    public function getLogger(): LoggerInterface { return $this->logger; }
-    public function preview(): void {}
-    public function execute(): void {}
+class TestableBaseCronJob extends BaseCronJob
+{
+    public function getUI(): CronUIInterface
+    {
+        return $this->ui;
+    }
+
+    public function getLogger(): LoggerInterface
+    {
+        return $this->logger;
+    }
+
+    public function preview(): void
+    {
+    }
+
+    public function execute(): void
+    {
+    }
 }
 
 class BaseCronJobTest extends TestCase

+ 6 - 4
tests/Unit/Service/Dolibarr/DolibarrApiServiceTest.php

@@ -45,7 +45,8 @@ class DolibarrApiServiceTest extends TestCase
     /**
      * @see DolibarrApiService::getSociety()
      */
-    public function testGetSocietyNotExisting(): void {
+    public function testGetSocietyNotExisting(): void
+    {
         $dolibarrApiService = $this->getMockBuilder(DolibarrApiService::class)
             ->setConstructorArgs([$this->client])
             ->setMethodsExcept(['getSociety'])
@@ -56,7 +57,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("thirdparties", [ "limit" => "1", "sqlfilters" => "ref_int=" . $organizationId])
+            ->with('thirdparties', ['limit' => '1', 'sqlfilters' => 'ref_int='.$organizationId])
             ->willThrowException(new HttpException(404));
 
         $society = $dolibarrApiService->getSociety($organizationId);
@@ -67,7 +68,8 @@ class DolibarrApiServiceTest extends TestCase
     /**
      * @see DolibarrApiService::getSociety()
      */
-    public function testGetSocietyWithError(): void {
+    public function testGetSocietyWithError(): void
+    {
         $dolibarrApiService = $this->getMockBuilder(DolibarrApiService::class)
             ->setConstructorArgs([$this->client])
             ->setMethodsExcept(['getSociety'])
@@ -80,7 +82,7 @@ class DolibarrApiServiceTest extends TestCase
         $dolibarrApiService
             ->expects(self::once())
             ->method('getJsonContent')
-            ->with("thirdparties", [ "limit" => "1", "sqlfilters" => "ref_int=" . $organizationId])
+            ->with('thirdparties', ['limit' => '1', 'sqlfilters' => 'ref_int='.$organizationId])
             ->willThrowException($e);
 
         $this->expectException($e::class);

+ 1 - 1
tests/Unit/Service/Dolibarr/DolibarrSyncServiceTest.php

@@ -855,7 +855,7 @@ class DolibarrSyncServiceTest extends TestCase
 
         $this->assertEqualsCanonicalizing([
             1 => [1 => [FunctionEnum::PRESIDENT->value], 2 => [FunctionEnum::STUDENT->value]],
-            2 => [3 => [FunctionEnum::PRESIDENT->value, FunctionEnum::TEACHER->value]]
+            2 => [3 => [FunctionEnum::PRESIDENT->value, FunctionEnum::TEACHER->value]],
         ], $index);
     }