Skip to content

Commit 13231d2

Browse files
committed
Merge remote-tracking branch 'origin/1.12.x' into 2.1.x
2 parents d2d18b4 + 7e3639b commit 13231d2

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

conf/config.neon

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,12 @@ services:
680680
-
681681
class: PHPStan\File\FileMonitor
682682
arguments:
683-
fileFinder: @fileFinderAnalyse
683+
analyseFileFinder: @fileFinderAnalyse
684+
scanFileFinder: @fileFinderScan
685+
analysedPaths: %analysedPaths%
686+
analysedPathsFromConfig: %analysedPathsFromConfig%
687+
scanFiles: %scanFiles%
688+
scanDirectories: %scanDirectories%
684689

685690
-
686691
class: PHPStan\Parser\DeclarePositionVisitor

src/Command/FixerApplication.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ public function run(
147147
});
148148

149149
$this->fileMonitor->initialize(array_merge(
150-
$this->analysedPaths,
151150
$this->getComposerLocks(),
152151
$this->getComposerInstalled(),
153152
$this->getExecutedFiles(),

src/File/FileMonitor.php

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
namespace PHPStan\File;
44

55
use PHPStan\ShouldNotHappenException;
6+
use function array_diff;
67
use function array_key_exists;
78
use function array_keys;
9+
use function array_merge;
10+
use function array_unique;
11+
use function is_dir;
12+
use function is_file;
813
use function sha1_file;
914

1015
final class FileMonitor
@@ -14,39 +19,52 @@ final class FileMonitor
1419
private ?array $fileHashes = null;
1520

1621
/** @var array<string>|null */
17-
private ?array $paths = null;
22+
private ?array $filePaths = null;
1823

19-
public function __construct(private FileFinder $fileFinder)
24+
/**
25+
* @param string[] $analysedPaths
26+
* @param string[] $analysedPathsFromConfig
27+
* @param string[] $scanFiles
28+
* @param string[] $scanDirectories
29+
*/
30+
public function __construct(
31+
private FileFinder $analyseFileFinder,
32+
private FileFinder $scanFileFinder,
33+
private array $analysedPaths,
34+
private array $analysedPathsFromConfig,
35+
private array $scanFiles,
36+
private array $scanDirectories,
37+
)
2038
{
2139
}
2240

2341
/**
24-
* @param array<string> $paths
42+
* @param array<string> $filePaths
2543
*/
26-
public function initialize(array $paths): void
44+
public function initialize(array $filePaths): void
2745
{
28-
$finderResult = $this->fileFinder->findFiles($paths);
46+
$finderResult = $this->analyseFileFinder->findFiles($this->analysedPaths);
2947
$fileHashes = [];
30-
foreach ($finderResult->getFiles() as $filePath) {
48+
foreach (array_merge($finderResult->getFiles(), $filePaths, $this->getScannedFiles($finderResult->getFiles())) as $filePath) {
3149
$fileHashes[$filePath] = $this->getFileHash($filePath);
3250
}
3351

3452
$this->fileHashes = $fileHashes;
35-
$this->paths = $paths;
53+
$this->filePaths = $filePaths;
3654
}
3755

3856
public function getChanges(): FileMonitorResult
3957
{
40-
if ($this->fileHashes === null || $this->paths === null) {
58+
if ($this->fileHashes === null || $this->filePaths === null) {
4159
throw new ShouldNotHappenException();
4260
}
43-
$finderResult = $this->fileFinder->findFiles($this->paths);
61+
$finderResult = $this->analyseFileFinder->findFiles($this->analysedPaths);
4462
$oldFileHashes = $this->fileHashes;
4563
$fileHashes = [];
4664
$newFiles = [];
4765
$changedFiles = [];
4866
$deletedFiles = [];
49-
foreach ($finderResult->getFiles() as $filePath) {
67+
foreach (array_merge($finderResult->getFiles(), $this->filePaths, $this->getScannedFiles($finderResult->getFiles())) as $filePath) {
5068
if (!array_key_exists($filePath, $oldFileHashes)) {
5169
$newFiles[] = $filePath;
5270
$fileHashes[$filePath] = $this->getFileHash($filePath);
@@ -88,4 +106,32 @@ private function getFileHash(string $filePath): string
88106
return $hash;
89107
}
90108

109+
/**
110+
* @param string[] $allAnalysedFiles
111+
* @return array<string>
112+
*/
113+
private function getScannedFiles(array $allAnalysedFiles): array
114+
{
115+
$scannedFiles = $this->scanFiles;
116+
$analysedDirectories = [];
117+
foreach (array_merge($this->analysedPaths, $this->analysedPathsFromConfig) as $analysedPath) {
118+
if (is_file($analysedPath)) {
119+
continue;
120+
}
121+
122+
if (!is_dir($analysedPath)) {
123+
continue;
124+
}
125+
126+
$analysedDirectories[] = $analysedPath;
127+
}
128+
129+
$directories = array_unique(array_merge($analysedDirectories, $this->scanDirectories));
130+
foreach ($this->scanFileFinder->findFiles($directories)->getFiles() as $file) {
131+
$scannedFiles[] = $file;
132+
}
133+
134+
return array_diff($scannedFiles, $allAnalysedFiles);
135+
}
136+
91137
}

0 commit comments

Comments
 (0)