Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 52 additions & 38 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,7 @@ abstract protected function getFieldSynopsisDefaultLinkend(): string;
abstract protected function getFieldSynopsisName(): string;

/** @param array<string, ConstInfo> $allConstInfos */
abstract protected function getFieldSynopsisValueString(array $allConstInfos): ?string;
abstract public function getFieldSynopsisValueString(array $allConstInfos): ?string;

abstract public function discardInfoForOldPhpVersions(?int $minimumPhpVersionIdCompatibility): void;

Expand Down Expand Up @@ -2644,7 +2644,7 @@ protected function getFieldSynopsisName(): string
}

/** @param array<string, ConstInfo> $allConstInfos */
protected function getFieldSynopsisValueString(array $allConstInfos): ?string
public function getFieldSynopsisValueString(array $allConstInfos): ?string
{
$value = EvaluatedValue::createFromExpression($this->value, null, $this->cValue, $allConstInfos);
if ($value->isUnknownConstValue) {
Expand All @@ -2663,32 +2663,41 @@ protected function getFieldSynopsisValueString(array $allConstInfos): ?string
private function getPredefinedConstantElement(
DOMDocument $doc,
int $indentationLevel,
string $name
string $name,
DOMNodeList $manualConstantElements
): DOMElement {
$indentation = str_repeat(" ", $indentationLevel);

$element = $doc->createElement($name);

$constantElement = $doc->createElement("constant");
$constantElement->textContent = $this->name->__toString();

$typeElement = ($this->phpDocType ?? $this->type)->getTypeForDoc($doc);

$element->appendChild(new DOMText("\n$indentation "));
$element->appendChild($constantElement);
foreach ($manualConstantElements as $i => $manualConstantElement) {
$constantElement = $doc->createElement("constant");
$constantElement->textContent = $manualConstantElement->textContent;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about using cloneNode() here instead of the manual element reconstruction (which was even more incomplete before)?

foreach ($manualConstantElement->attributes as $attribute) {
$constantElement->setAttribute($attribute->nodeName, $attribute->nodeValue);
}

if ($i > 0) {
$element->appendChild(new DOMText(","));
}
$element->appendChild(new DOMText("\n$indentation "));
$element->appendChild($constantElement);
}
$element->appendChild(new DOMText("\n$indentation ("));
$element->appendChild($typeElement);
$element->appendChild(new DOMText(")\n$indentation"));

return $element;
}

public function getPredefinedConstantTerm(DOMDocument $doc, int $indentationLevel): DOMElement {
return $this->getPredefinedConstantElement($doc, $indentationLevel, "term");
public function getPredefinedConstantTerm(DOMDocument $doc, int $indentationLevel, DOMNodeList $manualConstantElements): DOMElement {
return $this->getPredefinedConstantElement($doc, $indentationLevel, "term", $manualConstantElements);
}

public function getPredefinedConstantEntry(DOMDocument $doc, int $indentationLevel): DOMElement {
return $this->getPredefinedConstantElement($doc, $indentationLevel, "entry");
public function getPredefinedConstantEntry(DOMDocument $doc, int $indentationLevel, DOMNodeList $manualConstantElements): DOMElement {
return $this->getPredefinedConstantElement($doc, $indentationLevel, "entry", $manualConstantElements);
}

public function discardInfoForOldPhpVersions(?int $minimumPhpVersionIdCompatibility): void {
Expand Down Expand Up @@ -3150,7 +3159,7 @@ protected function getFieldSynopsisName(): string
}

/** @param array<string, ConstInfo> $allConstInfos */
protected function getFieldSynopsisValueString(array $allConstInfos): ?string
public function getFieldSynopsisValueString(array $allConstInfos): ?string
{
return $this->defaultValueString;
}
Expand Down Expand Up @@ -5731,7 +5740,8 @@ function replacePredefinedConstants(string $targetDirectory, array $constMap, ar
}

foreach ($entry->getElementsByTagName("term") as $manualTermElement) {
$manualConstantElement = $manualTermElement->getElementsByTagName("constant")->item(0);
$manualConstantElements = $manualTermElement->getElementsByTagName("constant");
$manualConstantElement = $manualConstantElements->item(0);
if (!$manualConstantElement instanceof DOMElement) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gen_stub --verify-manual now reports some constants as missing which are in in fact documented. As far as I can see, they appear in a row as a 2nd item. E.g.:

Warning: Missing predefined constant for Dom\INDEX_SIZE_ERR

continue;
}
Expand All @@ -5743,14 +5753,16 @@ function replacePredefinedConstants(string $targetDirectory, array $constMap, ar
continue;
}

$documentedConstMap[$manualConstantName] = $manualConstantName;
foreach ($manualConstantElements as $manualConstantElement) {
$documentedConstMap[$manualConstantElement->textContent] = $manualConstantElement->textContent;
}

if ($entry->firstChild instanceof DOMText) {
$indentationLevel = strlen(str_replace("\n", "", $entry->firstChild->textContent));
} else {
$indentationLevel = 3;
}
$newTermElement = $stubConstant->getPredefinedConstantTerm($doc, $indentationLevel);
$newTermElement = $stubConstant->getPredefinedConstantTerm($doc, $indentationLevel, $manualConstantElements);

if ($manualTermElement->textContent === $newTermElement->textContent) {
continue;
Expand All @@ -5771,34 +5783,36 @@ function replacePredefinedConstants(string $targetDirectory, array $constMap, ar
continue;
}

foreach ($entry->getElementsByTagName("constant") as $manualConstantElement) {
if (!$manualConstantElement instanceof DOMElement) {
continue;
}

$manualConstantName = $manualConstantElement->textContent;
$manualConstantElements = $entry->getElementsByTagName("constant");
$manualConstantElement = $manualConstantElements->item(0);
if (!$manualConstantElement instanceof DOMElement) {
continue;
}

$stubConstant = $constMap[$manualConstantName] ?? null;
if ($stubConstant === null) {
continue;
}
$manualConstantName = $manualConstantElement->textContent;

$documentedConstMap[$manualConstantName] = $manualConstantName;
$stubConstant = $constMap[$manualConstantName] ?? null;
if ($stubConstant === null) {
continue;
}

if ($row->firstChild instanceof DOMText) {
$indentationLevel = strlen(str_replace("\n", "", $row->firstChild->textContent));
} else {
$indentationLevel = 3;
}
$newEntryElement = $stubConstant->getPredefinedConstantEntry($doc, $indentationLevel);
foreach ($manualConstantElements as $manualConstantElement) {
$documentedConstMap[$manualConstantElement->textContent] = $manualConstantElement->textContent;
}

if ($entry->textContent === $newEntryElement->textContent) {
continue;
}
if ($row->firstChild instanceof DOMText) {
$indentationLevel = strlen(str_replace("\n", "", $row->firstChild->textContent));
} else {
$indentationLevel = 3;
}
$newEntryElement = $stubConstant->getPredefinedConstantEntry($doc, $indentationLevel, $manualConstantElements);

$entry->parentNode->replaceChild($newEntryElement, $entry);
$updated = true;
if ($entry->textContent === $newEntryElement->textContent) {
continue;
}

$entry->parentNode->replaceChild($newEntryElement, $entry);
$updated = true;
}

if ($updated) {
Expand Down
Loading