Skip to content

Commit

Permalink
Simplify PhpFilesFinder (#3649)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Apr 23, 2023
1 parent 8423831 commit 07a0475
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 43 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ parameters:
paths:
- bin/rector.php
- src/Bootstrap/RectorConfigsResolver.php
- src/ValueObject/StaticNonPhpFileSuffixes.php
- src/NonPhpFile/NonPhpFileProcessor.php
- tests/FileSystem/FilesFinder/FilesFinderTest.php

# part of tests
Expand Down
19 changes: 1 addition & 18 deletions src/FileSystem/PhpFilesFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,16 @@ public function __construct(
*/
public function findInPaths(array $paths): array
{
$filePaths = $this->filesFinder->findInDirectoriesAndFiles($paths);
$suffixRegexPattern = StaticNonPhpFileSuffixes::getSuffixRegexPattern();
$filePaths = $this->filesFinder->findInDirectoriesAndFiles($paths, ['php']);

// filter out non-PHP files
foreach ($filePaths as $key => $filePath) {
// $pathname = $filePath->getPathname();

/**
* check .blade.php early so next .php check in next if can be skipped
*/
if (str_ends_with($filePath, '.blade.php')) {
unset($filePaths[$key]);
continue;
}

/**
* obvious
*/
if (str_ends_with($filePath, '.php')) {
continue;
}

/**
* only check with regex when needed
*/
if (StringUtils::isMatch($filePath, $suffixRegexPattern)) {
unset($filePaths[$key]);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/NonPhpFile/NonPhpFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

final class NonPhpFileProcessor implements FileProcessorInterface
{
/**
* @var string[]
*/
private const SUFFIXES = ['neon', 'yaml', 'xml', 'yml', 'twig', 'latte', 'blade.php', 'tpl'];


/**
* @param NonPhpRectorInterface[] $nonPhpRectors
*/
Expand Down Expand Up @@ -86,7 +92,7 @@ public function supports(File $file, Configuration $configuration): bool
*/
public function getSupportedFileExtensions(): array
{
return StaticNonPhpFileSuffixes::SUFFIXES;
return self::SUFFIXES;
}

private function printFile(File $file, Configuration $configuration): void
Expand Down
23 changes: 0 additions & 23 deletions src/ValueObject/StaticNonPhpFileSuffixes.php

This file was deleted.

0 comments on commit 07a0475

Please sign in to comment.