rector/src/Caching/UnchangedFilesFilter.php

35 lines
933 B
PHP
Raw Permalink Normal View History

2020-04-01 01:55:44 +00:00
<?php
declare (strict_types=1);
namespace Rector\Caching;
2020-04-01 01:55:44 +00:00
use Rector\Caching\Detector\ChangedFilesDetector;
2020-04-01 01:55:44 +00:00
final class UnchangedFilesFilter
{
/**
* @readonly
* @var \Rector\Caching\Detector\ChangedFilesDetector
2020-04-01 01:55:44 +00:00
*/
private $changedFilesDetector;
public function __construct(ChangedFilesDetector $changedFilesDetector)
2020-04-01 01:55:44 +00:00
{
$this->changedFilesDetector = $changedFilesDetector;
}
/**
* @param string[] $filePaths
* @return string[]
2020-04-01 01:55:44 +00:00
*/
public function filterFileInfos(array $filePaths) : array
2020-04-01 01:55:44 +00:00
{
$changedFileInfos = [];
foreach ($filePaths as $filePath) {
if (!$this->changedFilesDetector->hasFileChanged($filePath)) {
2020-04-01 01:55:44 +00:00
continue;
}
$changedFileInfos[] = $filePath;
$this->changedFilesDetector->invalidateFile($filePath);
2020-04-01 01:55:44 +00:00
}
return \array_unique($changedFileInfos);
2020-04-01 01:55:44 +00:00
}
}