Skip to content

gen_stub: various simplifications and clean up (5) #18665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gen_stub: add ConstInfo::getPredefinedConstantElement()
Simplifies the implementation of `::getPredefinedConstantTerm()` and
`::getPredefinedConstantEntry()`, which only differ in the name of the tag
used.
  • Loading branch information
DanielEScherzer committed May 29, 2025
commit c562b69fc2e79d3ca242aad8f71f3fbbb18529c6
40 changes: 17 additions & 23 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2658,41 +2658,35 @@ protected function getFieldSynopsisValueString(array $allConstInfos): ?string
return $this->valueString;
}

public function getPredefinedConstantTerm(DOMDocument $doc, int $indentationLevel): DOMElement {
private function getPredefinedConstantElement(
DOMDocument $doc,
int $indentationLevel,
string $name
): DOMElement {
$indentation = str_repeat(" ", $indentationLevel);

$termElement = $doc->createElement("term");
$element = $doc->createElement($name);

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

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

$termElement->appendChild(new DOMText("\n$indentation "));
$termElement->appendChild($constantElement);
$termElement->appendChild(new DOMText("\n$indentation ("));
$termElement->appendChild($typeElement);
$termElement->appendChild(new DOMText(")\n$indentation"));
$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 $termElement;
return $element;
}

public function getPredefinedConstantEntry(DOMDocument $doc, int $indentationLevel): DOMElement {
$indentation = str_repeat(" ", $indentationLevel);

$entryElement = $doc->createElement("entry");

$constantElement = $doc->createElement("constant");
$constantElement->textContent = $this->name->__toString();
$typeElement = ($this->phpDocType ?? $this->type)->getTypeForDoc($doc);

$entryElement->appendChild(new DOMText("\n$indentation "));
$entryElement->appendChild($constantElement);
$entryElement->appendChild(new DOMText("\n$indentation ("));
$entryElement->appendChild($typeElement);
$entryElement->appendChild(new DOMText(")\n$indentation"));
public function getPredefinedConstantTerm(DOMDocument $doc, int $indentationLevel): DOMElement {
return $this->getPredefinedConstantElement($doc, $indentationLevel, "term");
}

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

public function discardInfoForOldPhpVersions(?int $phpVersionIdMinimumCompatibility): void {
Expand Down