Skip to content

Commit 79d0b1b

Browse files
fix: validate files in FilesSnapshot before processing
Add check to ensure each file is valid before processing. Without this change filemtime throws an error if the file doesn't exist but is part of cache, which is very common in dev environment. For production it won't matter since is_file is cached, for some reason is_file is also faster than file_exists. Symfony codebase also prefers is_file over file_exists when checking existence of php file.
1 parent 62552cb commit 79d0b1b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Cache/FilesSnapshot.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use ReflectionClass;
88

99
use function array_unique;
10+
use function is_file;
1011
use function Safe\filemtime;
1112

1213
class FilesSnapshot
@@ -24,6 +25,10 @@ public static function for(array $files): self
2425
$dependencies = [];
2526

2627
foreach (array_unique($files) as $file) {
28+
if (!is_file($file)) {
29+
continue;
30+
}
31+
2732
$dependencies[$file] = filemtime($file);
2833
}
2934

0 commit comments

Comments
 (0)