Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace scandir() with symfony finder #1002

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Task/Logfile/RotateLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Robo\Task\Logfile;

use Robo\Result;
use Symfony\Component\Finder\Finder;

/**
* Rotates a log (or any other) file
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}