diff --git a/src/Symfony/Component/HttpFoundation/File/File.php b/src/Symfony/Component/HttpFoundation/File/File.php index 45f344e375315..da3c7ed5d20ad 100644 --- a/src/Symfony/Component/HttpFoundation/File/File.php +++ b/src/Symfony/Component/HttpFoundation/File/File.php @@ -54,11 +54,10 @@ public function __construct(string $path, bool $checkPath = true) */ public function guessExtension() { - if (!class_exists(MimeTypes::class)) { - throw new \LogicException('You cannot guess the extension as the Mime component is not installed. Try running "composer require symfony/mime".'); - } + // Do not inline this + $mimeType = $this->getMimeType(); - return MimeTypes::getDefault()->getExtensions($this->getMimeType())[0] ?? null; + return MimeTypes::getDefault()->getExtensions($mimeType)[0] ?? null; } /** @@ -74,6 +73,10 @@ public function guessExtension() */ public function getMimeType() { + if (!class_exists(MimeTypes::class)) { + throw new \LogicException('You cannot guess the mime type as the Mime component is not installed. Try running "composer require symfony/mime".'); + } + return MimeTypes::getDefault()->guessMimeType($this->getPathname()); }