Skip to content

Commit 93605f2

Browse files
authored
Make the usage of the role attribute more clear (#9901)
Currently, the role attribute is mainly used to differentiate OO and procedural "aliases" when they are documented on the same page (e.g. https://www.php.net/manual/en/datetime.diff.php). However, these function-method counterparts are not always aliases in fact according to the stubs (#9491). That's why sometimes the usage of the role attribute is ambiguous, thus syncing the manual with the stubs results in false positive diffs. This change fixes the problem by a very obtrusive way: by changing the value of all role="oop" attributes to the actual class name, like role="DateTime", and by getting rid of all role="procedural" attributes as they became unnecessary. This way, class synopsis pages can clearly reference methods, and skip functions. Additionally, gen_stub.php will be able to generate the correct methodsynopsis role even though a single page describes multiple methods, like `DateTime/DateTimeImmutable/DateTimeInterface::diff()`.
1 parent e45afbf commit 93605f2

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

build/gen_stub.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,14 +1487,10 @@ public function getMethodSynopsisElement(array $funcMap, array $aliasMap, DOMDoc
14871487

14881488
$methodSynopsis = $doc->createElement($synopsisType);
14891489

1490-
$aliasedFunc = $this->aliasType === "alias" && isset($funcMap[$this->alias->__toString()]) ? $funcMap[$this->alias->__toString()] : null;
1491-
$aliasFunc = $aliasMap[$this->name->__toString()] ?? null;
1492-
1493-
if (($this->aliasType === "alias" && $aliasedFunc !== null && $aliasedFunc->isMethod() !== $this->isMethod()) ||
1494-
($aliasFunc !== null && $aliasFunc->isMethod() !== $this->isMethod())
1495-
) {
1490+
if ($this->isMethod()) {
1491+
assert($this->name instanceof MethodName);
14961492
$role = $doc->createAttribute("role");
1497-
$role->value = $this->isMethod() ? "oop" : "procedural";
1493+
$role->value = $this->name->className->__toString();
14981494
$methodSynopsis->appendChild($role);
14991495
}
15001496

@@ -2772,7 +2768,7 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap, itera
27722768
$classSynopsis->appendChild(new DOMText("\n "));
27732769
$includeElement = $this->createIncludeElement(
27742770
$doc,
2775-
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[not(@role='procedural')])"
2771+
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[@role='$this->name'])"
27762772
);
27772773
$classSynopsis->appendChild($includeElement);
27782774
}
@@ -2781,7 +2777,7 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap, itera
27812777
$classSynopsis->appendChild(new DOMText("\n "));
27822778
$includeElement = $this->createIncludeElement(
27832779
$doc,
2784-
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[not(@role='procedural')])"
2780+
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role='$this->name'])"
27852781
);
27862782
$classSynopsis->appendChild($includeElement);
27872783
}
@@ -2790,7 +2786,7 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap, itera
27902786
$classSynopsis->appendChild(new DOMText("\n "));
27912787
$includeElement = $this->createIncludeElement(
27922788
$doc,
2793-
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:destructorsynopsis[not(@role='procedural')])"
2789+
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:destructorsynopsis[@role='$this->name'])"
27942790
);
27952791
$classSynopsis->appendChild($includeElement);
27962792
}
@@ -2807,7 +2803,7 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap, itera
28072803
$parentReference = self::getClassSynopsisReference($parent);
28082804
$includeElement = $this->createIncludeElement(
28092805
$doc,
2810-
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$parentReference')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[not(@role='procedural')])"
2806+
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$parentReference')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role='$parent')])"
28112807
);
28122808
$classSynopsis->appendChild($includeElement);
28132809
}

0 commit comments

Comments
 (0)