mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-13 06:32:22 +00:00
[Core] Add Smarty Support for PhpFilesFinder check non-PHP files (#736)
This commit is contained in:
parent
b422a9d747
commit
af1cbb92fd
|
@ -116,7 +116,6 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$scope = $foreach->expr->getAttribute(AttributeKey::SCOPE);
|
||||
|
||||
if (! $scope instanceof Scope) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,16 @@ use Symplify\SmartFileSystem\SmartFileInfo;
|
|||
|
||||
final class PhpFilesFinder
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private const NON_PHP_FILE_EXTENSIONS = [
|
||||
// Laravel
|
||||
'.blade.php',
|
||||
// Smarty
|
||||
'.tpl',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private FilesFinder $filesFinder,
|
||||
private UnchangedFilesFilter $unchangedFilesFilter
|
||||
|
@ -23,11 +33,16 @@ final class PhpFilesFinder
|
|||
{
|
||||
$phpFileInfos = $this->filesFinder->findInDirectoriesAndFiles($paths);
|
||||
|
||||
// filter out non-PHP php files, e.g. blade templates in Laravel
|
||||
$phpFileInfos = array_filter(
|
||||
$phpFileInfos,
|
||||
fn (SmartFileInfo $smartFileInfo): bool => ! \str_ends_with($smartFileInfo->getPathname(), '.blade.php')
|
||||
);
|
||||
// filter out non-PHP files
|
||||
foreach ($phpFileInfos as $key => $phpFileInfo) {
|
||||
$pathName = $phpFileInfo->getPathname();
|
||||
foreach (self::NON_PHP_FILE_EXTENSIONS as $nonPHPFileExtension) {
|
||||
if (str_ends_with($pathName, $nonPHPFileExtension)) {
|
||||
unset($phpFileInfos[$key]);
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->unchangedFilesFilter->filterAndJoinWithDependentFileInfos($phpFileInfos);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user