app\models\File::getCoverFileUnderSameDirectory PHP Method

getCoverFileUnderSameDirectory() private method

Some albums have its own cover image under the same directory as cover|folder.jpg/png. We'll check if such a cover file is found, and use it if positive.
private getCoverFileUnderSameDirectory ( ) : string | false
return string | false The cover file's full path, or false if none found
    private function getCoverFileUnderSameDirectory()
    {
        // As directory scanning can be expensive, we cache and reuse the result.
        $cacheKey = md5($this->path . '_cover');
        if (!is_null($cover = Cache::get($cacheKey))) {
            return $cover;
        }
        $matches = array_keys(iterator_to_array(Finder::create()->depth(0)->ignoreUnreadableDirs()->files()->followLinks()->name('/(cov|fold)er\\.(jpe?g|png)$/i')->in(dirname($this->path))));
        $cover = $matches ? $matches[0] : false;
        // Even if a file is found, make sure it's a real image.
        if ($cover && exif_imagetype($cover) === false) {
            $cover = false;
        }
        Cache::put($cacheKey, $cover, 24 * 60);
        return $cover;
    }