Olivier Massot 9 miesięcy temu
rodzic
commit
46ccf498b4

+ 3 - 4
src/Message/Handler/OrganizationDeletionHandler.php

@@ -17,8 +17,8 @@ readonly class OrganizationDeletionHandler
 {
     public function __construct(
         private OrganizationFactory $organizationFactory,
-        private MailerInterface     $symfonyMailer,
-        private string              $opentalentMailReport,
+        private MailerInterface $symfonyMailer,
+        private string $opentalentMailReport,
     ) {
     }
 
@@ -55,8 +55,7 @@ readonly class OrganizationDeletionHandler
         string $to,
         string $subject,
         string $content,
-    ): void
-    {
+    ): void {
         $symfonyMail = (new SymfonyEmail())
             ->from($this->opentalentMailReport)
             ->replyTo($this->opentalentMailReport)

+ 6 - 6
src/Service/Organization/OrganizationFactory.php

@@ -179,7 +179,7 @@ class OrganizationFactory
             $this->logger->warning('-- Operation ended with errors, check the logs for more information --');
         } else {
             $organizationCreationRequest->setStatus(OrganizationCreationRequest::STATUS_OK);
-            $this->logger->info("The organization has been created (id=".$organization->getId().").");
+            $this->logger->info('The organization has been created (id='.$organization->getId().').');
         }
 
         return $organization;
@@ -829,7 +829,7 @@ class OrganizationFactory
 
             $this->entityManager->flush();
             $this->entityManager->commit();
-            $this->logger->info("Organization deleted");
+            $this->logger->info('Organization deleted');
         } catch (\Exception $e) {
             $this->logger->critical("An error happened, operation cancelled\n".$e);
             $this->entityManager->rollback();
@@ -838,7 +838,7 @@ class OrganizationFactory
 
         try {
             $this->deleteTypo3Website($organizationDeletionRequest->getOrganizationId());
-            $this->logger->info("Typo3 website deleted");
+            $this->logger->info('Typo3 website deleted');
         } catch (\Exception $e) {
             $this->logger->critical('An error happened while deleting the Typo3 website, please proceed manually.');
             $this->logger->debug($e);
@@ -847,7 +847,7 @@ class OrganizationFactory
 
         try {
             $this->switchDolibarrSocietyToProspect($organizationDeletionRequest->getOrganizationId());
-            $this->logger->info("Dolibarr society switched to prospect");
+            $this->logger->info('Dolibarr society switched to prospect');
         } catch (\Exception $e) {
             $this->logger->critical('An error happened while updating the Dolibarr society, please proceed manually.');
             $this->logger->debug($e);
@@ -856,7 +856,7 @@ class OrganizationFactory
 
         try {
             $this->fileManager->deleteOrganizationFiles($organizationDeletionRequest->getOrganizationId());
-            $this->logger->info("Organization files deleted");
+            $this->logger->info('Organization files deleted');
         } catch (\RuntimeException $e) {
             // Nothing to delete
         } catch (\Exception $e) {
@@ -886,7 +886,7 @@ class OrganizationFactory
         }
 
         $this->logger->info(
-            "The organization has been deleted."
+            'The organization has been deleted.'
         );
 
         return $organizationDeletionRequest;

+ 13 - 10
src/Service/Utils/FileUtils.php

@@ -6,6 +6,7 @@ namespace App\Service\Utils;
 
 use App\Entity\Core\File;
 use Mimey\MimeTypes;
+use Path\Exception\FileExistsException;
 use Path\Exception\FileNotFoundException;
 use Path\Exception\IOException;
 use Path\Path;
@@ -19,12 +20,9 @@ class FileUtils
 
     /**
      * Return a Path object
-     * > Method is for testing purposes
+     * > Method is for testing purposes.
      *
      * @see https://path-php.net/api
-     *
-     * @param string $path
-     * @return Path
      */
     protected function makePath(string $path): Path
     {
@@ -33,10 +31,9 @@ class FileUtils
 
     /**
      * Return a FileLocator object
-     * > Method is for testing purposes
+     * > Method is for testing purposes.
      *
      * @param array<string> $directories
-     * @return FileLocator
      */
     protected function makeFileLocator(array $directories): FileLocator
     {
@@ -93,6 +90,11 @@ class FileUtils
         return PathUtils::join($tempDir, uniqid($prefix).'.'.$ext);
     }
 
+    /**
+     * @throws IOException
+     * @throws FileNotFoundException
+     * @throws FileExistsException
+     */
     public function rmIfExist(string $path): void
     {
         $this->makePath($path)->remove_p();
@@ -102,9 +104,11 @@ class FileUtils
      * Reads the content of a file.
      *
      * @param string $path the path to the file to be read
+     *
      * @return string the content of the file
-     * @throws \Path\Exception\FileNotFoundException
-     * @throws \Path\Exception\IOException
+     *
+     * @throws FileNotFoundException
+     * @throws IOException
      */
     public function getFileContent(string $path): string
     {
@@ -140,9 +144,8 @@ class FileUtils
     /**
      * List the files located in the given directory.
      *
-     * @param string $path
-     * @param string $glob
      * @return list<string>
+     *
      * @throws FileNotFoundException
      * @throws IOException
      */

+ 2 - 4
src/Service/Utils/PathUtils.php

@@ -4,8 +4,6 @@ declare(strict_types=1);
 
 namespace App\Service\Utils;
 
-use Path\Exception\FileNotFoundException;
-use Path\Exception\IOException;
 use Path\Path;
 
 /**
@@ -18,7 +16,7 @@ class PathUtils
      */
     public static function getProjectDir(): string
     {
-        return (string)(new Path(__FILE__))->parent(4);
+        return (string) (new Path(__FILE__))->parent(4);
     }
 
     /**
@@ -49,6 +47,6 @@ class PathUtils
 
         $basePath = array_shift($paths);
 
-        return (string)(new Path($basePath))->append(...$paths);
+        return (string) (new Path($basePath))->append(...$paths);
     }
 }

+ 25 - 14
tests/Unit/Service/Utils/FileUtilsTest.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace App\Tests\Unit\Service\Utils;
@@ -10,7 +11,8 @@ use PHPUnit\Framework\MockObject\MockObject;
 use PHPUnit\Framework\TestCase;
 use Symfony\Component\Config\FileLocator;
 
-class TestableFileUtils extends FileUtils {
+class TestableFileUtils extends FileUtils
+{
     public function makePath(string $path): Path
     {
         return parent::makePath($path);
@@ -32,7 +34,8 @@ class FileUtilsTest extends TestCase
             ->getMock();
     }
 
-    public function testGetMimeTypeFromExt() {
+    public function testGetMimeTypeFromExt()
+    {
         $fileUtils = $this->getMockFor('getMimeTypeFromExt');
 
         $this->assertEquals(
@@ -51,7 +54,8 @@ class FileUtilsTest extends TestCase
         );
     }
 
-    public function testGetMimeTypeFromFilename() {
+    public function testGetMimeTypeFromFilename()
+    {
         $fileUtils = $this->getMockFor('guessMimeTypeFromFilename');
 
         $fileUtils->method('getMimeTypeFromExt')->with('png')->willReturn('image/png');
@@ -62,7 +66,8 @@ class FileUtilsTest extends TestCase
         );
     }
 
-    public function testIsImage() {
+    public function testIsImage()
+    {
         $fileUtils = $this->getMockFor('isImage');
 
         // has a registered mimetype
@@ -89,7 +94,8 @@ class FileUtilsTest extends TestCase
         $this->assertFalse($fileUtils->isImage($file3));
     }
 
-    public function testGetTempFilename() {
+    public function testGetTempFilename()
+    {
         $fileUtils = $this->getMockFor('getTempFilename');
 
         $tempDirPath = $this->getMockBuilder(Path::class)->disableOriginalConstructor()->getMock();
@@ -103,7 +109,8 @@ class FileUtilsTest extends TestCase
         );
     }
 
-    public function testGetTempFilenameWithPrefix() {
+    public function testGetTempFilenameWithPrefix()
+    {
         $fileUtils = $this->getMockFor('getTempFilename');
 
         $tempDirPath = $this->getMockBuilder(Path::class)->disableOriginalConstructor()->getMock();
@@ -117,7 +124,8 @@ class FileUtilsTest extends TestCase
         );
     }
 
-    public function testRmIfExist() {
+    public function testRmIfExist()
+    {
         $fileUtils = $this->getMockFor('rmIfExist');
 
         $myPath = '/path/to/something';
@@ -130,7 +138,8 @@ class FileUtilsTest extends TestCase
         $fileUtils->rmIfExist($myPath);
     }
 
-    public function testGetFileContent() {
+    public function testGetFileContent()
+    {
         $fileUtils = $this->getMockFor('getFileContent');
 
         $myPath = '/path/to/something';
@@ -143,7 +152,8 @@ class FileUtilsTest extends TestCase
         $this->assertEquals('my content', $fileUtils->getFileContent($myPath));
     }
 
-    public function testLocate() {
+    public function testLocate()
+    {
         $fileUtils = $this->getMockFor('locate');
 
         $fileLocator = $this->getMockBuilder(FileLocator::class)->disableOriginalConstructor()->getMock();
@@ -162,7 +172,8 @@ class FileUtilsTest extends TestCase
         );
     }
 
-    public function testLocateNotFound() {
+    public function testLocateNotFound()
+    {
         $fileUtils = $this->getMockFor('locate');
 
         $fileLocator = $this->getMockBuilder(FileLocator::class)->disableOriginalConstructor()->getMock();
@@ -181,7 +192,8 @@ class FileUtilsTest extends TestCase
         );
     }
 
-    public function testList() {
+    public function testList()
+    {
         $fileUtils = $this->getMockFor('list');
 
         $path = $this->getMockBuilder(Path::class)->disableOriginalConstructor()->getMock();
@@ -206,7 +218,8 @@ class FileUtilsTest extends TestCase
         );
     }
 
-    public function testListWithGlob() {
+    public function testListWithGlob()
+    {
         $fileUtils = $this->getMockFor('list');
 
         $path = $this->getMockBuilder(Path::class)->disableOriginalConstructor()->getMock();
@@ -230,6 +243,4 @@ class FileUtilsTest extends TestCase
             $fileUtils->list('/home', '*.pdf')
         );
     }
-
-
 }