Skip to content

Commit 38fe46c

Browse files
committed
build/gen_stub: include attribute arguments in synopsis modifiers
1 parent 6f0aa11 commit 38fe46c

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

build/gen_stub.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,7 @@ public function getMethodSynopsisElement(DOMDocument $doc): ?DOMElement {
20752075
$methodSynopsis->appendChild(new DOMText("\n "));
20762076

20772077
foreach ($this->attributes as $attribute) {
2078-
$modifier = $doc->createElement("modifier", "#[\\" . $attribute->class . "]");
2078+
$modifier = $doc->createElement("modifier", (string) $attribute);
20792079
$modifier->setAttribute("role", "attribute");
20802080
$methodSynopsis->appendChild($modifier);
20812081
$methodSynopsis->appendChild(new DOMText("\n "));
@@ -2112,7 +2112,7 @@ public function getMethodSynopsisElement(DOMDocument $doc): ?DOMElement {
21122112

21132113
$methodSynopsis->appendChild($methodparam);
21142114
foreach ($arg->attributes as $attribute) {
2115-
$attribute = $doc->createElement("modifier", "#[\\" . $attribute->class . "]");
2115+
$attribute = $doc->createElement("modifier", (string) $attribute);
21162116
$attribute->setAttribute("role", "attribute");
21172117

21182118
$methodparam->appendChild($attribute);
@@ -3294,6 +3294,25 @@ public function __construct(
32943294
private readonly array $args,
32953295
) {}
32963296

3297+
public function __toString(): string {
3298+
$code = "#[\\" . $this->class;
3299+
if (!empty($this->args)) {
3300+
$prettyPrinter = new Standard;
3301+
$args = [];
3302+
foreach ($this->args as $arg) {
3303+
$argStr = '';
3304+
if ($arg->name !== null) {
3305+
$argStr .= $arg->name->name . ': ';
3306+
}
3307+
$argStr .= $prettyPrinter->prettyPrintExpr($arg->value);
3308+
$args[] = $argStr;
3309+
}
3310+
$code .= "(" . implode(", ", $args) . ")";
3311+
}
3312+
$code .= "]";
3313+
return $code;
3314+
}
3315+
32973316
/**
32983317
* @param array<string, ConstInfo> $allConstInfos
32993318
* @param array<string, string> &$declaredStrings Map of string content to
@@ -3959,7 +3978,7 @@ private static function createOoElement(
39593978
$ooElement->appendChild(new DOMText("\n$indentation "));
39603979
} elseif ($isMainClass) {
39613980
foreach ($classInfo->attributes as $attribute) {
3962-
$modifier = $doc->createElement("modifier", "#[\\" . $attribute->class . "]");
3981+
$modifier = $doc->createElement("modifier", (string) $attribute);
39633982
$modifier->setAttribute("role", "attribute");
39643983
$ooElement->appendChild($modifier);
39653984
$ooElement->appendChild(new DOMText("\n$indentation "));

0 commit comments

Comments
 (0)