Skip to content

Commit

Permalink
isVariadic() - do not attempt to read a nonexistent reflection file
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 21, 2020
1 parent 86c11d3 commit 3ea4fc3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 17 additions & 15 deletions src/Reflection/Php/PhpFunctionReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,24 @@ private function isVariadic(): bool
$isNativelyVariadic = $this->reflection->isVariadic();
if (!$isNativelyVariadic && $this->reflection->getFileName() !== false) {
$fileName = $this->reflection->getFileName();
$functionName = $this->reflection->getName();
$modifiedTime = filemtime($fileName);
if ($modifiedTime === false) {
$modifiedTime = time();
}
$variableCacheKey = sprintf('%d-v1', $modifiedTime);
$key = sprintf('variadic-function-%s-%s', $functionName, $fileName);
$cachedResult = $this->cache->load($key, $variableCacheKey);
if ($cachedResult === null) {
$nodes = $this->parser->parseFile($fileName);
$result = $this->callsFuncGetArgs($nodes);
$this->cache->save($key, $variableCacheKey, $result);
return $result;
}
if (file_exists($fileName)) {
$functionName = $this->reflection->getName();
$modifiedTime = filemtime($fileName);
if ($modifiedTime === false) {
$modifiedTime = time();
}
$variableCacheKey = sprintf('%d-v1', $modifiedTime);
$key = sprintf('variadic-function-%s-%s', $functionName, $fileName);
$cachedResult = $this->cache->load($key, $variableCacheKey);
if ($cachedResult === null) {
$nodes = $this->parser->parseFile($fileName);
$result = $this->callsFuncGetArgs($nodes);
$this->cache->save($key, $variableCacheKey, $result);
return $result;
}

return $cachedResult;
return $cachedResult;
}
}

return $isNativelyVariadic;
Expand Down
2 changes: 1 addition & 1 deletion src/Reflection/Php/PhpMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private function isVariadic(): bool
$filename = $this->declaringTrait->getFileName();
}

if (!$isNativelyVariadic && $filename !== false) {
if (!$isNativelyVariadic && $filename !== false && file_exists($filename)) {
$modifiedTime = filemtime($filename);
if ($modifiedTime === false) {
$modifiedTime = time();
Expand Down

0 comments on commit 3ea4fc3

Please sign in to comment.