Skip to content

Commit 3ea4fc3

Browse files
committed
isVariadic() - do not attempt to read a nonexistent reflection file
1 parent 86c11d3 commit 3ea4fc3

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/Reflection/Php/PhpFunctionReflection.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,24 @@ private function isVariadic(): bool
163163
$isNativelyVariadic = $this->reflection->isVariadic();
164164
if (!$isNativelyVariadic && $this->reflection->getFileName() !== false) {
165165
$fileName = $this->reflection->getFileName();
166-
$functionName = $this->reflection->getName();
167-
$modifiedTime = filemtime($fileName);
168-
if ($modifiedTime === false) {
169-
$modifiedTime = time();
170-
}
171-
$variableCacheKey = sprintf('%d-v1', $modifiedTime);
172-
$key = sprintf('variadic-function-%s-%s', $functionName, $fileName);
173-
$cachedResult = $this->cache->load($key, $variableCacheKey);
174-
if ($cachedResult === null) {
175-
$nodes = $this->parser->parseFile($fileName);
176-
$result = $this->callsFuncGetArgs($nodes);
177-
$this->cache->save($key, $variableCacheKey, $result);
178-
return $result;
179-
}
166+
if (file_exists($fileName)) {
167+
$functionName = $this->reflection->getName();
168+
$modifiedTime = filemtime($fileName);
169+
if ($modifiedTime === false) {
170+
$modifiedTime = time();
171+
}
172+
$variableCacheKey = sprintf('%d-v1', $modifiedTime);
173+
$key = sprintf('variadic-function-%s-%s', $functionName, $fileName);
174+
$cachedResult = $this->cache->load($key, $variableCacheKey);
175+
if ($cachedResult === null) {
176+
$nodes = $this->parser->parseFile($fileName);
177+
$result = $this->callsFuncGetArgs($nodes);
178+
$this->cache->save($key, $variableCacheKey, $result);
179+
return $result;
180+
}
180181

181-
return $cachedResult;
182+
return $cachedResult;
183+
}
182184
}
183185

184186
return $isNativelyVariadic;

src/Reflection/Php/PhpMethodReflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private function isVariadic(): bool
263263
$filename = $this->declaringTrait->getFileName();
264264
}
265265

266-
if (!$isNativelyVariadic && $filename !== false) {
266+
if (!$isNativelyVariadic && $filename !== false && file_exists($filename)) {
267267
$modifiedTime = filemtime($filename);
268268
if ($modifiedTime === false) {
269269
$modifiedTime = time();

0 commit comments

Comments
 (0)