[Core] Add Smarty Support for PhpFilesFinder check non-PHP files (#736)

This commit is contained in:
Abdul Malik Ikhsan 2021-08-23 03:52:24 +07:00 committed by GitHub
parent b422a9d747
commit af1cbb92fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -116,7 +116,6 @@ CODE_SAMPLE
}
$scope = $foreach->expr->getAttribute(AttributeKey::SCOPE);
if (! $scope instanceof Scope) {
return true;
}

View File

@ -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);
}