rector/packages/Caching/UnchangedFilesFilter.php
Abdul Malik Ikhsan fc10fce13d
[Rectify] [Php81] Enable Rectify on Readonly Property only (#1384)
* re-enable rectify and ecs

* [Rectify] [Php81] Enable Rectify on Readonly Property only

* comment

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
2021-12-04 15:32:52 +03:00

46 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Rector\Caching;
use Rector\Caching\Detector\ChangedFilesDetector;
use Symplify\SmartFileSystem\SmartFileInfo;
final class UnchangedFilesFilter
{
public function __construct(
private readonly ChangedFilesDetector $changedFilesDetector
) {
}
/**
* @param SmartFileInfo[] $fileInfos
* @return SmartFileInfo[]
*/
public function filterAndJoinWithDependentFileInfos(array $fileInfos): array
{
$changedFileInfos = [];
$dependentFileInfos = [];
foreach ($fileInfos as $fileInfo) {
if (! $this->changedFilesDetector->hasFileChanged($fileInfo)) {
continue;
}
$changedFileInfos[] = $fileInfo;
$this->changedFilesDetector->invalidateFile($fileInfo);
$dependentFileInfos = array_merge(
$dependentFileInfos,
$this->changedFilesDetector->getDependentFileInfos($fileInfo)
);
}
// add dependent files
$dependentFileInfos = array_merge($dependentFileInfos, $changedFileInfos);
return array_unique($dependentFileInfos);
}
}