Fix documentation generation when legacy arginfo is generated

When legacy arginfo is generated, all the type info gets lost. Since this task is performed before any other additional functionalities of gen_stub.php (e.g. verification, method synopsis and class synopsis generation), these fail as they would require the missing type information.

The issue is fixed by deep cloning the file info objects (albeit only their affected properties), so that we use those for legacy arginfo generation, leaving the original ones untouched.
This commit is contained in:
Máté Kocsis 2021-09-10 08:12:16 +02:00
parent 6ee96f095a
commit 73063db5c8
No known key found for this signature in database
GPG Key ID: FD055E41728BF310

View File

@ -71,14 +71,16 @@ function processStubFile(string $stubFile, Context $context): ?FileInfo {
}
if ($fileInfo->generateLegacyArginfo) {
foreach ($fileInfo->getAllFuncInfos() as $funcInfo) {
$legacyFileInfo = clone $fileInfo;
foreach ($legacyFileInfo->getAllFuncInfos() as $funcInfo) {
$funcInfo->discardInfoForOldPhpVersions();
}
foreach ($fileInfo->getAllPropertyInfos() as $propertyInfo) {
foreach ($legacyFileInfo->getAllPropertyInfos() as $propertyInfo) {
$propertyInfo->discardInfoForOldPhpVersions();
}
$arginfoCode = generateArgInfoCode($fileInfo, $stubHash);
$arginfoCode = generateArgInfoCode($legacyFileInfo, $stubHash);
if (($context->forceRegeneration || $stubHash !== $oldStubHash) && file_put_contents($legacyFile, $arginfoCode)) {
echo "Saved $legacyFile\n";
}
@ -1324,6 +1326,14 @@ class FuncInfo {
return $methodSynopsis;
}
public function __clone()
{
foreach ($this->args as $key => $argInfo) {
$this->args[$key] = clone $argInfo;
}
$this->return = clone $this->return;
}
}
function initializeZval(string $zvalName, $value): string
@ -1555,6 +1565,13 @@ class PropertyInfo
return $evaluator->evaluateDirectly($this->defaultValue);
}
public function __clone()
{
if ($this->type) {
$this->type = clone $this->type;
}
}
}
class EnumCaseInfo {
@ -2045,6 +2062,17 @@ class ClassInfo {
return $includeElement;
}
public function __clone()
{
foreach ($this->propertyInfos as $key => $propertyInfo) {
$this->propertyInfos[$key] = clone $propertyInfo;
}
foreach ($this->funcInfos as $key => $funcInfo) {
$this->funcInfos[$key] = clone $funcInfo;
}
}
}
class FileInfo {
@ -2079,6 +2107,17 @@ class FileInfo {
yield from $classInfo->propertyInfos;
}
}
public function __clone()
{
foreach ($this->funcInfos as $key => $funcInfo) {
$this->funcInfos[$key] = clone $funcInfo;
}
foreach ($this->classInfos as $key => $classInfo) {
$this->classInfos[$key] = clone $classInfo;
}
}
}
class DocCommentTag {