@@ -32,7 +32,7 @@ abstract class AbstractDocumentFactory
3232 public function __construct (
3333 FilesystemOperator $ documentsStorage ,
3434 DocumentFinderInterface $ documentFinder ,
35- ?LoggerInterface $ logger = null
35+ ?LoggerInterface $ logger = null ,
3636 ) {
3737 if (!$ documentsStorage instanceof MountManager) {
3838 trigger_error ('Document Storage must be a MountManager to address public and private files. ' , E_USER_WARNING );
@@ -42,69 +42,56 @@ public function __construct(
4242 $ this ->logger = $ logger ?? new NullLogger ();
4343 }
4444
45- /**
46- * @return File
47- */
4845 public function getFile (): File
4946 {
5047 if (null === $ this ->file ) {
5148 throw new \BadMethodCallException ('File should be defined before using it. ' );
5249 }
50+
5351 return $ this ->file ;
5452 }
5553
5654 /**
57- * @param File $file
5855 * @return $this
5956 */
6057 public function setFile (File $ file ): static
6158 {
6259 $ this ->file = $ file ;
60+
6361 return $ this ;
6462 }
6563
66- /**
67- * @return FolderInterface|null
68- */
6964 public function getFolder (): ?FolderInterface
7065 {
7166 return $ this ->folder ;
7267 }
7368
7469 /**
75- * @param FolderInterface|null $folder
7670 * @return $this
7771 */
7872 public function setFolder (?FolderInterface $ folder = null ): static
7973 {
8074 $ this ->folder = $ folder ;
75+
8176 return $ this ;
8277 }
8378
8479 /**
8580 * Special case for SVG without XML statement.
86- *
87- * @param DocumentInterface $document
8881 */
8982 protected function parseSvgMimeType (DocumentInterface $ document ): void
9083 {
9184 if (
92- ($ document ->getMimeType () === 'text/plain ' || $ document ->getMimeType () === ' text/html ' ) &&
93- preg_match ('#\.svg$# ' , $ document ->getFilename ())
85+ (' text/plain ' === $ document ->getMimeType () || 'text/html ' === $ document ->getMimeType ())
86+ && preg_match ('#\.svg$# ' , $ document ->getFilename ())
9487 ) {
9588 $ this ->logger ->debug ('Uploaded a SVG without xml declaration. Presuming it’s a valid SVG file. ' );
9689 $ document ->setMimeType ('image/svg+xml ' );
9790 }
9891 }
9992
100- /**
101- * @return DocumentInterface
102- */
10393 abstract protected function createDocument (): DocumentInterface ;
10494
105- /**
106- * @param DocumentInterface $document
107- */
10895 abstract protected function persistDocument (DocumentInterface $ document ): void ;
10996
11097 protected function getHashAlgorithm (): string
@@ -116,14 +103,14 @@ protected function getHashAlgorithm(): string
116103 * Create a document from UploadedFile, Be careful, this method does not flush, only
117104 * persists current Document.
118105 *
119- * @param bool $allowEmpty Default false, requires a local file to create new document entity
106+ * @param bool $allowEmpty Default false, requires a local file to create new document entity
120107 * @param bool $allowDuplicates Default false, always import new document even if file already exists
121- * @return null|DocumentInterface
108+ *
122109 * @throws FilesystemException
123110 */
124111 public function getDocument (bool $ allowEmpty = false , bool $ allowDuplicates = false ): ?DocumentInterface
125112 {
126- if ($ allowEmpty === false ) {
113+ if (false === $ allowEmpty ) {
127114 // Getter throw exception on null file
128115 $ file = $ this ->getFile ();
129116 } else {
@@ -147,8 +134,8 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
147134 $ existingDocument = $ this ->documentFinder ->findOneByHashAndAlgorithm ($ fileHash , $ this ->getHashAlgorithm ());
148135 if (null !== $ existingDocument ) {
149136 if (
150- $ existingDocument ->isRaw () &&
151- null !== $ existingDownscaledDocument = $ existingDocument ->getDownscaledDocument ()
137+ $ existingDocument ->isRaw ()
138+ && null !== $ existingDownscaledDocument = $ existingDocument ->getDownscaledDocument ()
152139 ) {
153140 $ existingDocument = $ existingDownscaledDocument ;
154141 }
@@ -160,6 +147,7 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
160147 'File %s already exists with same checksum, do not upload it twice. ' ,
161148 $ existingDocument ->getFilename ()
162149 ));
150+
163151 return $ existingDocument ;
164152 }
165153 }
@@ -175,8 +163,8 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
175163 $ this ->parseSvgMimeType ($ document );
176164
177165 if (
178- $ document instanceof FileHashInterface &&
179- false !== $ fileHash
166+ $ document instanceof FileHashInterface
167+ && false !== $ fileHash
180168 ) {
181169 $ document ->setFileHash ($ fileHash );
182170 $ document ->setFileHashAlgorithm ($ this ->getHashAlgorithm ());
@@ -196,8 +184,6 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
196184 /**
197185 * Updates a document from UploadedFile, Be careful, this method does not flush.
198186 *
199- * @param DocumentInterface $document
200- * @return DocumentInterface
201187 * @throws FilesystemException
202188 */
203189 public function updateDocument (DocumentInterface $ document ): DocumentInterface
@@ -231,7 +217,7 @@ public function updateDocument(DocumentInterface $document): DocumentInterface
231217 }
232218 }
233219
234- $ document ->setFolder (\mb_substr (hash (" crc32b " , date ('YmdHi ' )), 0 , 12 ));
220+ $ document ->setFolder (\mb_substr (hash (' crc32b ' , date ('YmdHi ' )), 0 , 12 ));
235221 }
236222
237223 $ document ->setFilename ($ this ->getFileName ());
@@ -247,9 +233,6 @@ public function updateDocument(DocumentInterface $document): DocumentInterface
247233 }
248234
249235 /**
250- * @param File $localFile
251- * @param DocumentInterface $document
252- * @return void
253236 * @throws FilesystemException
254237 */
255238 public function moveFile (File $ localFile , DocumentInterface $ document ): void
@@ -267,9 +250,6 @@ public function moveFile(File $localFile, DocumentInterface $document): void
267250 }
268251 }
269252
270- /**
271- * @return string
272- */
273253 protected function getFileName (): string
274254 {
275255 $ file = $ this ->getFile ();
@@ -278,8 +258,8 @@ protected function getFileName(): string
278258 $ fileName = $ file ->getClientOriginalName ();
279259 } elseif (
280260 $ file instanceof DownloadedFile
281- && $ file ->getOriginalFilename () !== null
282- && $ file ->getOriginalFilename () !== ''
261+ && null !== $ file ->getOriginalFilename ()
262+ && '' !== $ file ->getOriginalFilename ()
283263 ) {
284264 $ fileName = $ file ->getOriginalFilename ();
285265 } else {
@@ -292,9 +272,6 @@ protected function getFileName(): string
292272 /**
293273 * Create a Document from an external URL.
294274 *
295- * @param string $downloadUrl
296- *
297- * @return DocumentInterface|null
298275 * @throws FilesystemException
299276 */
300277 public function getDocumentFromUrl (string $ downloadUrl ): ?DocumentInterface
@@ -303,6 +280,7 @@ public function getDocumentFromUrl(string $downloadUrl): ?DocumentInterface
303280 if (null !== $ downloadedFile ) {
304281 return $ this ->setFile ($ downloadedFile )->getDocument ();
305282 }
283+
306284 return null ;
307285 }
308286}
0 commit comments