2020-04-01 01:55:44 +00:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\Caching;
|
2020-04-01 01:55:44 +00:00
|
|
|
|
2022-06-06 17:12:56 +00:00
|
|
|
use Rector\Caching\Detector\ChangedFilesDetector;
|
2020-04-01 01:55:44 +00:00
|
|
|
final class UnchangedFilesFilter
|
|
|
|
{
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2021-05-10 23:39:21 +00:00
|
|
|
* @var \Rector\Caching\Detector\ChangedFilesDetector
|
2020-04-01 01:55:44 +00:00
|
|
|
*/
|
|
|
|
private $changedFilesDetector;
|
2022-06-07 08:22:29 +00:00
|
|
|
public function __construct(ChangedFilesDetector $changedFilesDetector)
|
2020-04-01 01:55:44 +00:00
|
|
|
{
|
|
|
|
$this->changedFilesDetector = $changedFilesDetector;
|
|
|
|
}
|
|
|
|
/**
|
2022-09-01 09:30:44 +00:00
|
|
|
* @param string[] $filePaths
|
|
|
|
* @return string[]
|
2020-04-01 01:55:44 +00:00
|
|
|
*/
|
2023-08-11 11:32:21 +00:00
|
|
|
public function filterFileInfos(array $filePaths) : array
|
2020-04-01 01:55:44 +00:00
|
|
|
{
|
|
|
|
$changedFileInfos = [];
|
2022-09-01 09:30:44 +00:00
|
|
|
foreach ($filePaths as $filePath) {
|
|
|
|
if (!$this->changedFilesDetector->hasFileChanged($filePath)) {
|
2020-04-01 01:55:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-09-01 09:30:44 +00:00
|
|
|
$changedFileInfos[] = $filePath;
|
|
|
|
$this->changedFilesDetector->invalidateFile($filePath);
|
2020-04-01 01:55:44 +00:00
|
|
|
}
|
2023-08-11 11:32:21 +00:00
|
|
|
return \array_unique($changedFileInfos);
|
2020-04-01 01:55:44 +00:00
|
|
|
}
|
|
|
|
}
|