From 85022eb22529d962807c44b50e43dbe993bf3faf Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 15 Jan 2025 09:49:01 +0700 Subject: [PATCH] use ->ignoreVCSIgnored() on RectorConfigBuilder::withRootFiles() over custom logic --- src/Configuration/RectorConfigBuilder.php | 49 +---------------------- 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/src/Configuration/RectorConfigBuilder.php b/src/Configuration/RectorConfigBuilder.php index 2c09bdbcb7..c47c87d3a0 100644 --- a/src/Configuration/RectorConfigBuilder.php +++ b/src/Configuration/RectorConfigBuilder.php @@ -4,7 +4,6 @@ namespace Rector\Configuration; -use Nette\Utils\FileSystem; use Rector\Bridge\SetProviderCollector; use Rector\Bridge\SetRectorsResolver; use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface; @@ -378,52 +377,11 @@ public function withSkipPath(string $skipPath): self */ public function withRootFiles(): self { - $gitIgnoreContents = []; - if (file_exists(getcwd() . '/.gitignore')) { - $gitIgnoreContents = array_filter( - iterator_to_array(FileSystem::readLines(getcwd() . '/.gitignore')), - function (string $string): bool { - $string = trim($string); - - // new line - if ($string === '') { - return false; - } - - // comment - if (str_starts_with($string, '#')) { - return false; - } - - // normalize - $string = ltrim($string, '/\\'); - - // files in deep directory, no need to be in lists - if (str_contains($string, '/') || str_contains($string, '\\')) { - return false; - } - - // only files - return is_file($string); - } - ); - - // make realpath collection - $gitIgnoreContents = array_map( - function (string $string): string { - // normalize - $string = ltrim($string, '/\\'); - - return realpath($string); - }, - $gitIgnoreContents - ); - } - $rootPhpFilesFinder = (new Finder())->files() ->in(getcwd()) ->depth(0) ->ignoreDotFiles(false) + ->ignoreVCSIgnored(true) ->name('*.php') ->name('.*.php') // this file cannot be interpreted as PHP file @@ -433,11 +391,6 @@ function (string $string): string { foreach ($rootPhpFilesFinder as $rootPhpFileFinder) { $path = $rootPhpFileFinder->getRealPath(); - - if (in_array($path, $gitIgnoreContents, true)) { - continue; - } - $this->paths[] = $path; }