Skip to content

Commit

Permalink
[Core] Add Smarty Support for PhpFilesFinder check non-PHP files (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Aug 22, 2021
1 parent b422a9d commit af1cbb9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ private function shouldSkip(Foreach_ $foreach): bool
}

$scope = $foreach->expr->getAttribute(AttributeKey::SCOPE);

if (! $scope instanceof Scope) {
return true;
}
Expand Down
25 changes: 20 additions & 5 deletions src/FileSystem/PhpFilesFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@

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
Expand All @@ -23,11 +33,16 @@ public function findInPaths(array $paths): array
{
$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);
}
Expand Down

0 comments on commit af1cbb9

Please sign in to comment.