rector/vendor/symplify/smart-file-system/src/Finder/FinderSanitizer.php
Tomas Votruba 4e3847e1bc Updated Rector to commit 3c07468691132d0246e55627495a1e7d4cd76a8d
3c07468691 [DX] Localize few PackageBuilder classes (#2884)
2022-09-01 19:50:06 +00:00

39 lines
1.2 KiB
PHP

<?php
declare (strict_types=1);
namespace RectorPrefix202209\Symplify\SmartFileSystem\Finder;
use RectorPrefix202209\Nette\Utils\Finder as NetteFinder;
use SplFileInfo;
use RectorPrefix202209\Symfony\Component\Finder\Finder as SymfonyFinder;
use RectorPrefix202209\Symfony\Component\Finder\SplFileInfo as SymfonySplFileInfo;
use Symplify\SmartFileSystem\SmartFileInfo;
/**
* @see \Symplify\SmartFileSystem\Tests\Finder\FinderSanitizer\FinderSanitizerTest
*/
final class FinderSanitizer
{
/**
* @param NetteFinder|SymfonyFinder|mixed[] $files
* @return SmartFileInfo[]
*/
public function sanitize($files) : array
{
$smartFileInfos = [];
foreach ($files as $file) {
$fileInfo = \is_string($file) ? new SplFileInfo($file) : $file;
if (!$this->isFileInfoValid($fileInfo)) {
continue;
}
/** @var string $realPath */
$realPath = $fileInfo->getRealPath();
$smartFileInfos[] = new SmartFileInfo($realPath);
}
return $smartFileInfos;
}
private function isFileInfoValid(SplFileInfo $fileInfo) : bool
{
return (bool) $fileInfo->getRealPath();
}
}