diff --git a/src/Mime/Mapping/APK.php b/src/Mime/Mapping/APK.php index e93b479..145070f 100644 --- a/src/Mime/Mapping/APK.php +++ b/src/Mime/Mapping/APK.php @@ -1,5 +1,15 @@ filePath = $filePath; + return $this; } @@ -27,11 +39,13 @@ public function forFile(string $filePath): self * Set the upload object for fallback extension guessing. * * @param UploadedFile $upload + * * @return $this */ public function withUpload(UploadedFile $upload): self { $this->upload = $upload; + return $this; } @@ -39,6 +53,7 @@ public function withUpload(UploadedFile $upload): self * Determine the MIME type of the file. * * @throws ValidationException + * * @return string|null */ public function getMimeType(): ?string @@ -106,6 +121,7 @@ private function detectUsingMagicBytes(): ?string * Check if the file is a valid APK by inspecting its contents. * * @param string $filePath + * * @return bool */ private function isApk(string $filePath): bool @@ -117,22 +133,24 @@ private function isApk(string $filePath): bool foreach ($requiredFiles as $file) { if ($zip->locateName($file) === false) { $zip->close(); + return false; // Required APK-specific file not found } } $zip->close(); + return true; // All required files found } return false; // Not a valid ZIP file } - /** * Determine the file extension based on the MIME type or original extension. * - * @param array $whitelistedExtensions Whitelisted extensions for validation - * @param string|null $originalExtension Original client extension + * @param array $whitelistedExtensions Whitelisted extensions for validation + * @param string|null $originalExtension Original client extension + * * @return string */ public function getFileExtension(array $whitelistedExtensions = [], ?string $originalExtension = null): string @@ -166,6 +184,7 @@ public function getFileExtension(array $whitelistedExtensions = [], ?string $ori * Guess file extension based on MIME type. * * @param string|null $mimeType + * * @return string|null */ private function guessExtensionFromMimeType(?string $mimeType): ?string diff --git a/src/Providers/MimeMappingProvider.php b/src/Providers/MimeMappingProvider.php index 43fdcb3..b839ba4 100644 --- a/src/Providers/MimeMappingProvider.php +++ b/src/Providers/MimeMappingProvider.php @@ -1,5 +1,15 @@ $mappingClass::getMimeType(), - 'extension' => $mappingClass::getExtension(), + 'mime' => $mappingClass::getMimeType(), + 'extension' => $mappingClass::getExtension(), 'magicBytes' => $mappingClass::getMagicBytes(), ]; } diff --git a/src/Repositories/FileRepository.php b/src/Repositories/FileRepository.php index e6e518e..24aa7eb 100644 --- a/src/Repositories/FileRepository.php +++ b/src/Repositories/FileRepository.php @@ -133,7 +133,7 @@ public function moveUploadedFileToTemp(UploadedFileInterface $upload): ?Upload * Fatal error: Uncaught Laminas\HttpHandlerRunner\Exception\EmitterException: * Output has been emitted previously; cannot emit response */ - $tempFile = @tempnam($this->path . '/tmp', 'fof.upload.'); + $tempFile = @tempnam($this->path.'/tmp', 'fof.upload.'); $upload->moveTo($tempFile); $file = new Upload( @@ -248,10 +248,10 @@ public function matchFilesForPost(Post $post): void File::query() // Files already mapped to the post. - ->whereHas('posts', fn($query) => $query->where('posts.id', $post->id)) + ->whereHas('posts', fn ($query) => $query->where('posts.id', $post->id)) // Files found in (new) content. ->orWhereExists( - fn($query) => $query + fn ($query) => $query ->select($db->raw(1)) ->from('posts') ->where('posts.id', $post->id) @@ -378,7 +378,7 @@ public function generateFilenameFor(File $file, bool $withFolder = false): strin { $today = (new Carbon()); - $path = $today->timestamp . '-' . $today->micro . '-' . $file->base_name; + $path = $today->timestamp.'-'.$today->micro.'-'.$file->base_name; return $withFolder ? sprintf( '%s%s%s', @@ -428,6 +428,6 @@ public function getUrlForFile(File $file): ?string return null; } - return $this->getHostnameForFile($file, $adapter) . '/' . $file->path; + return $this->getHostnameForFile($file, $adapter).'/'.$file->path; } }