PHP 7.3.9: Check if uploaded file is an image (I don't care about the format) I just care if it's any of the common formats so that later when I list all files, for those that are images, I can generate previews based on mime type.

So PHP.NET suggest to use exif_imagetype function to check if file is an image. In case of success an integer will be returned indicating one of 18 constants.

The check I do is against an UploadedFile so my method is quite simple. As this is code review. Would you optimize my code to be even better? Thanks for any hints.

/**
 * @link https://www.php.net/manual/en/function.exif-imagetype.php
 *
 * @param UploadedFile $file
 * @return bool
 */
private function isFileImage(UploadedFile $file): bool
{
    $result = exif_imagetype($file-&gt;getRealPath());

    return is_int($result) &amp;&amp; $result &gt;= 1 &amp;&amp; $result &lt;= 18;
}
The method in question does not use $this therefore you might consider making it static.

Further it is a private method, i dont know of which class, but consider making it a public method of its own class.

The method accepts UploadedFile but it is only interested in the real path. As long as you keep it private it could be ok and simpler to call, but if you ever make it public (as suggested above), you should let it accept string path instead, that way it will be more flexible.

There are 18 constants for the image types, but you are using hardcoded numbers. What If another type is added in the future? Do you want to have to modify your code? Check the exif_ imagetype return value doc. It will never return int that is not one of the constants. return is_int($result); is absolutely enough.