protected function rotateSnapshots()
    {
        $finder = new Finder();
        $finder->in($this->directory)->sort(function (SplFileInfo $a, SplFileInfo $b) {
            return $b->getMTime() - $a->getMTime();
        });

        $count = 0;
        foreach ($finder as $file) {
            $count++;
            if ($count > $this->maxFiles) {
                try {
                    $this->files->delete($file->getRealPath());
                } catch (FilesException $e) {
                    // ignore
                }
            }
        }
    }