Flysystem - Sort By Last Modified

Since the ListWith plugin is removed from Filesystem, we must look for another way to retrieve the files sorted by timestamp however, It seems the lastModified attribute is always NULL, in my workaround the lastModified is requested for each file, so maybe not very efficient.

use League\Flysystem\StorageAttributes;

$listContents = $filesystem->listContents('')
    ->filter(fn (StorageAttributes $attributes) => $attributes->isFile())

$contents = [];

foreach ($listContents as $listContent) {
    $pathinfo = pathinfo($listContent->path());

    $contents[] = [
        'path' => $listContent->path(),
        'dirname' => $pathinfo['dirname'],
        'basename' => $pathinfo['basename'],
        'extension' => $pathinfo['extension'],
        'filename' => $pathinfo['filename'],
        'lastModified' => $filesystem->lastModified($listContent->path())

usort($contents, function ($a, $b) {
    return $a['lastModified'] <=> $b['lastModified'];