Olivier Massot 1 рік тому
батько
коміт
cc56006de3

+ 5 - 4
src/Service/Export/Encoder/DocXEncoder.php

@@ -7,7 +7,6 @@ namespace App\Service\Export\Encoder;
 use App\Enum\Export\ExportFormatEnum;
 use App\Service\Utils\FileUtils;
 use Phpdocx\Create\CreateDocx;
-use Throwable;
 
 /**
  * Encode HTML to docx format.
@@ -16,8 +15,9 @@ class DocXEncoder implements EncoderInterface
 {
     public function __construct(
         private readonly CreateDocx $phpDocx,
-        private readonly FileUtils $fileUtils
-    ) {}
+        private readonly FileUtils $fileUtils,
+    ) {
+    }
 
     public function support(string $format): bool
     {
@@ -31,7 +31,8 @@ class DocXEncoder implements EncoderInterface
      * return the encoded content.
      *
      * @param array<string, mixed> $options
-     * @throws Throwable
+     *
+     * @throws \Throwable
      */
     public function encode(string $html, array $options = []): string
     {

+ 7 - 4
src/Service/Export/Encoder/PdfEncoder.php

@@ -17,7 +17,8 @@ class PdfEncoder implements EncoderInterface
     protected Options $domPdfOptions;
     protected Dompdf $dompdf;
 
-    public function __construct() {
+    public function __construct()
+    {
         $this->domPdfOptions = new Options();
         $this->dompdf = new Dompdf();
     }
@@ -30,16 +31,17 @@ class PdfEncoder implements EncoderInterface
     /**
      * Converts the provided HTML content into a PDF document.
      *
-     * @param string $html The HTML content to be converted to PDF.
+     * @param string               $html    the HTML content to be converted to PDF
      * @param array<string, mixed> $options Optional configuration settings for the PDF generation
+     *
      *                                      @see https://github.com/dompdf/dompdf/blob/master/src/Options.php
      *
-     * @return string The generated PDF content as a string.
+     * @return string the generated PDF content as a string
      */
     public function encode(string $html, array $options = []): string
     {
         $this->domPdfOptions->setIsRemoteEnabled(true);
-        $this->domPdfOptions->setChroot(Path::getProjectDir() . '/public');
+        $this->domPdfOptions->setChroot(Path::getProjectDir().'/public');
         $this->domPdfOptions->setDefaultPaperOrientation('portrait');
         $this->domPdfOptions->setDefaultPaperSize('A4');
         $this->domPdfOptions->set($options);
@@ -47,6 +49,7 @@ class PdfEncoder implements EncoderInterface
         $this->dompdf->setOptions($this->domPdfOptions);
         $this->dompdf->loadHtml($html);
         $this->dompdf->render();
+
         return $this->dompdf->output();
     }
 }

+ 1 - 1
src/Service/File/Storage/ApiLegacyStorage.php

@@ -20,7 +20,7 @@ class ApiLegacyStorage implements FileStorageInterface
         protected readonly DataManager $dataManager,
         protected readonly UrlBuilder $urlBuilder,
         protected readonly string $legacyBaseUrl,
-        protected readonly string $publicLegacyBaseUrl
+        protected readonly string $publicLegacyBaseUrl,
     ) {
     }
 

+ 7 - 9
src/Service/Utils/FileUtils.php

@@ -6,7 +6,6 @@ namespace App\Service\Utils;
 
 use App\Entity\Core\File;
 use Mimey\MimeTypes;
-use RuntimeException;
 
 class FileUtils
 {
@@ -51,21 +50,19 @@ class FileUtils
      * Génère un nom de fichier temporaire situé dans le répertoire var/tmp,
      * avec l'extension et le préfixe donnés.
      *
-     * @param string $ext
-     * @param string $prefix
-     * @return string
-     * @throws RuntimeException
+     * @throws \RuntimeException
      */
     public function getTempFilename(string $ext = 'tmp', string $prefix = ''): string
     {
         if (empty($ext)) {
-            throw new RuntimeException('Extension can not be empty');
+            throw new \RuntimeException('Extension can not be empty');
         }
-        $tempDir = Path::getProjectDir() . '/var/tmp';
+        $tempDir = Path::getProjectDir().'/var/tmp';
         if (!is_dir($tempDir)) {
             mkdir($tempDir);
         }
-        return $tempDir . '/' . $prefix . uniqid() . '.' . $ext;
+
+        return $tempDir.'/'.$prefix.uniqid().'.'.$ext;
     }
 
     public function unlinkIfExist(string $path): void
@@ -75,7 +72,8 @@ class FileUtils
         }
     }
 
-    public function getFileContent(string $path): string {
+    public function getFileContent(string $path): string
+    {
         return file_get_contents($path);
     }
 }

+ 2 - 3
src/Service/Utils/UrlBuilder.php

@@ -4,8 +4,6 @@ declare(strict_types=1);
 
 namespace App\Service\Utils;
 
-use Symfony\Component\Routing\Generator\UrlGenerator;
-
 /**
  * Building url utilities.
  */
@@ -97,7 +95,8 @@ class UrlBuilder
     public function getRelativeUrl(string $url): string
     {
         $parts = parse_url($url);
-        return ($parts['path'] ?? '') . (isset($parts['query']) ? '?'.$parts['query'] : '');
+
+        return ($parts['path'] ?? '').(isset($parts['query']) ? '?'.$parts['query'] : '');
     }
 
     /**

+ 1 - 1
src/State/Processor/Export/LicenceCmf/ExportRequestProcessor.php

@@ -23,7 +23,7 @@ class ExportRequestProcessor implements ProcessorInterface
         private Security $security,
         private MessageBusInterface $messageBus,
         private ExporterIterator $handler,
-        private NetworkUtils $networkUtils
+        private NetworkUtils $networkUtils,
     ) {
     }
 

+ 9 - 5
tests/Unit/Service/Export/Encoder/DocXEncoderTest.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace App\Tests\Unit\Service\Export\Encoder;
@@ -11,10 +12,11 @@ use PHPUnit\Framework\TestCase;
 
 class DocXEncoderTest extends TestCase
 {
-    private MockObject | CreateDocx $phpDocx;
-    private MockObject | FileUtils $fileUtils;
+    private MockObject|CreateDocx $phpDocx;
+    private MockObject|FileUtils $fileUtils;
 
-    public function setUp(): void {
+    public function setUp(): void
+    {
         $this->phpDocx = $this->getMockBuilder(CreateDocx::class)->disableOriginalConstructor()->getMock();
         $this->fileUtils = $this->getMockBuilder(FileUtils::class)->disableOriginalConstructor()->getMock();
     }
@@ -30,7 +32,8 @@ class DocXEncoderTest extends TestCase
         $this->assertFalse($encoder->support('txt'));
     }
 
-    public function testEncode(): void {
+    public function testEncode(): void
+    {
         $encoder = $this->getMockBuilder(DocXEncoder::class)
             ->setConstructorArgs([$this->phpDocx, $this->fileUtils])
             ->setMethodsExcept(['encode'])
@@ -69,7 +72,8 @@ class DocXEncoderTest extends TestCase
         );
     }
 
-    public function testEncodeWithError(): void {
+    public function testEncodeWithError(): void
+    {
         $encoder = $this->getMockBuilder(DocXEncoder::class)
             ->setConstructorArgs([$this->phpDocx, $this->fileUtils])
             ->setMethodsExcept(['encode'])

+ 7 - 6
tests/Unit/Service/Export/Encoder/PdfEncoderTest.php

@@ -6,16 +6,17 @@ use App\Service\Export\Encoder\PdfEncoder;
 use App\Service\Utils\Path;
 use Dompdf\Dompdf;
 use Dompdf\Options;
-use Knp\Snappy\Pdf;
-use PHPUnit\Framework\MockObject\MockObject;
 use PHPUnit\Framework\TestCase;
 
-class TestablePdfEncoder extends PdfEncoder {
-    public function setDomPdfOptions(Options $options): void {
+class TestablePdfEncoder extends PdfEncoder
+{
+    public function setDomPdfOptions(Options $options): void
+    {
         $this->domPdfOptions = $options;
     }
 
-    public function setDomPdf(Dompdf $dompdf): void {
+    public function setDomPdf(Dompdf $dompdf): void
+    {
         $this->dompdf = $dompdf;
     }
 }
@@ -52,7 +53,7 @@ class PdfEncoderTest extends TestCase
         $encoder->setDomPdf($domPdf);
 
         $domPdfOptions->expects(self::once())->method('setIsRemoteEnabled')->with(true);
-        $domPdfOptions->expects(self::once())->method('setChroot')->with(Path::getProjectDir() . '/public');
+        $domPdfOptions->expects(self::once())->method('setChroot')->with(Path::getProjectDir().'/public');
         $domPdfOptions->expects(self::once())->method('setDefaultPaperOrientation')->with('portrait');
         $domPdfOptions->expects(self::once())->method('setDefaultPaperSize')->with('A4');
         $domPdfOptions->expects(self::once())->method('set')->with(['additionalOption' => 2]);