@@ -41,7 +41,7 @@ public function processAndOverrideDocument(?DocumentInterface $document = null):
4141 $ documentPath = $ document ->getMountPath ();
4242 $ processedImage = $ this ->getProcessedImage ($ documentPath );
4343
44- if (null === $ processedImage ) {
44+ if (null === $ documentPath || null === $ processedImage ) {
4545 return ;
4646 }
4747
@@ -69,7 +69,7 @@ public function processDocumentFromExistingRaw(?DocumentInterface $document = nu
6969
7070 $ processedImage = $ this ->getProcessedImage ($ documentPath );
7171
72- if (null === $ processedImage ) {
72+ if (null === $ documentPath || null === $ processedImage ) {
7373 return ;
7474 }
7575
@@ -195,8 +195,13 @@ private function storeNewProcessedImage(DocumentInterface $document, ImageInterf
195195 */
196196 private function writeNewProcessedImage (DocumentInterface $ document , ImageInterface $ image ): void
197197 {
198+ $ mountPath = $ document ->getMountPath ();
199+ if (null === $ mountPath ) {
200+ return ;
201+ }
202+
198203 $ this ->documentsStorage ->write (
199- $ document -> getMountPath () ,
204+ $ mountPath ,
200205 $ image ->encode (new AutoEncoder (quality: 100 ))->toString ()
201206 );
202207 }
@@ -247,7 +252,10 @@ private function updateDocumentFileHash(DocumentInterface $document): void
247252 */
248253 private function overwriteExistingProcessedImage (DocumentInterface $ document , ImageInterface $ image ): DocumentInterface
249254 {
250- $ this ->documentsStorage ->delete ($ document ->getMountPath ());
255+ if (null === $ mountPath = $ document ->getMountPath ()) {
256+ return $ document ;
257+ }
258+ $ this ->documentsStorage ->delete ($ mountPath );
251259 $ this ->writeNewProcessedImage ($ document , $ image );
252260 $ this ->updateDocumentImageSize ($ document , $ image );
253261 $ this ->updateDocumentFileHash ($ document );
@@ -269,6 +277,8 @@ private function generateRawFilename(string $filename): string
269277
270278 /**
271279 * Check if a document is valid for processing.
280+ *
281+ * @phpstan-assert-if-true DocumentInterface $document
272282 */
273283 private function isValidDocument (?DocumentInterface $ document ): bool
274284 {
0 commit comments