diff --git a/src/Task/Logfile/RotateLog.php b/src/Task/Logfile/RotateLog.php index 326ab7ad4..6e156871a 100644 --- a/src/Task/Logfile/RotateLog.php +++ b/src/Task/Logfile/RotateLog.php @@ -3,6 +3,7 @@ namespace Robo\Task\Logfile; use Robo\Result; +use Symfony\Component\Finder\Finder; /** * Rotates a log (or any other) file @@ -84,8 +85,7 @@ private function loadLogfile(string $logfile): self private function process(): self { $rotation = 0; - foreach (scandir($this->logfile->getPath(), SCANDIR_SORT_DESCENDING) as $origin) { - $origin = new \SplFileInfo($this->logfile->getPath().'/'.$origin); + foreach ($this->createFinder() as $origin) { if ($origin->isFile() && $this->isLogfile($origin)) { if ($this->version($origin) < $this->keep) { $rotated = $this->rotate($origin); @@ -160,4 +160,16 @@ private function rotate(\SplFileInfo $origin): string return $rotated; } + + /** + * @return Finder + */ + private function createFinder(): Finder + { + return (new Finder())->files() + ->depth(0) + ->sortByName() + ->reverseSorting() + ->in($this->logfile->getPath()); + } }