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

[Configuration] use ->ignoreVCSIgnored(true) on RectorConfigBuilder::withRootFiles() over custom logic #6669

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
49 changes: 1 addition & 48 deletions src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
Loading