Skip to content

Fix class synopsis generation #7891

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

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 11 additions & 13 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1540,9 +1540,9 @@ public function getFieldSynopsisElement(DOMDocument $doc): DOMElement
$fieldsynopsisElement->appendChild(new DOMText("\n "));
$fieldsynopsisElement->appendChild($this->getFieldSynopsisType()->getTypeForDoc($doc));

$className = str_replace("\\", "-", $this->name->class->toLowerString());
$className = str_replace(["\\", "_"], ["-", "-"], $this->name->class->toLowerString());
$varnameElement = $doc->createElement("varname", $this->name->property);
$varnameElement->setAttribute("linkend", "$className.props." . strtolower($this->name->property));
$varnameElement->setAttribute("linkend", "$className.props." . strtolower(str_replace("_", "-", $this->name->property)));
$fieldsynopsisElement->appendChild(new DOMText("\n "));
$fieldsynopsisElement->appendChild($varnameElement);

Expand All @@ -1558,14 +1558,14 @@ public function getFieldSynopsisElement(DOMDocument $doc): DOMElement
}

private function getFieldSynopsisType(): Type {
if ($this->type) {
Copy link
Member Author

Choose a reason for hiding this comment

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

We have a readonly mixed property which is indeed a resource. On the contrary, the real type is displayed for params and returns because their PHPDoc type hint is usually invalid (e.g. true, false|null etc.)

return $this->type;
}

if ($this->phpDocType) {
return $this->phpDocType;
}

if ($this->type) {
return $this->type;
}

throw new Exception("A property must have a type");
}

Expand Down Expand Up @@ -2005,11 +2005,11 @@ private static function createOoElement(
}

public static function getClassSynopsisFilename(Name $name): string {
return strtolower(implode('-', $name->parts));
return strtolower(str_replace("_", "-", implode('-', $name->parts)));
}

public static function getClassSynopsisReference(Name $name): string {
return "class." . strtolower(implode('-', $name->parts));
return "class." . self::getClassSynopsisFilename($name);
}

/**
Expand All @@ -2019,10 +2019,6 @@ public static function getClassSynopsisReference(Name $name): string {
*/
private function collectInheritedMembers(array &$parentsWithInheritedProperties, array &$parentsWithInheritedMethods, array $classMap): void
{
if ($this->type !== "class") {
Copy link
Member Author

Choose a reason for hiding this comment

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

usually, inherited members of interfaces are also displayed in the manual

return;
}

foreach ($this->extends as $parent) {
$parentInfo = $classMap[$parent->toString()] ?? null;
if (!$parentInfo) {
Expand All @@ -2033,7 +2029,7 @@ private function collectInheritedMembers(array &$parentsWithInheritedProperties,
$parentsWithInheritedProperties[$parent->toString()] = $parent;
}

if (!empty($parentInfo->funcInfos) && !isset($parentsWithInheritedMethods[$parent->toString()])) {
if (!isset($parentsWithInheritedMethods[$parent->toString()]) && $parentInfo->hasMethods()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

on the other hand, constructors are usually not displayed as inherited members.

$parentsWithInheritedMethods[$parent->toString()] = $parent;
}

Expand Down Expand Up @@ -2986,12 +2982,14 @@ function replaceClassSynopses(string $targetDirectory, array $classMap): array
$replacedXml = preg_replace(
[
"/REPLACED-ENTITY-([A-Za-z0-9._{}%-]+?;)/",
"/<phpdoc:(classref|exceptionref)\s+xmlns:phpdoc=\"([a-z0-9.:\/]+)\"\s+xmlns=\"([a-z0-9.:\/]+)\"\s+xml:id=\"([a-z0-9._-]+)\"\s*>/i",
"/<phpdoc:(classref|exceptionref)\s+xmlns:phpdoc=\"([a-z0-9.:\/]+)\"\s+xmlns=\"([a-z0-9.:\/]+)\"\s+xmlns:xi=\"([a-z0-9.:\/]+)\"\s+xml:id=\"([a-z0-9._-]+)\"\s*>/i",
"/<phpdoc:(classref|exceptionref)\s+xmlns:phpdoc=\"([a-z0-9.:\/]+)\"\s+xmlns=\"([a-z0-9.:\/]+)\"\s+xmlns:xlink=\"([a-z0-9.:\/]+)\"\s+xmlns:xi=\"([a-z0-9.:\/]+)\"\s+xml:id=\"([a-z0-9._-]+)\"\s*>/i",
"/<phpdoc:(classref|exceptionref)\s+xmlns=\"([a-z0-9.:\/]+)\"\s+xmlns:xlink=\"([a-z0-9.:\/]+)\"\s+xmlns:xi=\"([a-z0-9.:\/]+)\"\s+xmlns:phpdoc=\"([a-z0-9.:\/]+)\"\s+xml:id=\"([a-z0-9._-]+)\"\s*>/i",
],
[
"&$1",
"<phpdoc:$1 xml:id=\"$4\" xmlns:phpdoc=\"$2\" xmlns=\"$3\">",
"<phpdoc:$1 xml:id=\"$5\" xmlns:phpdoc=\"$2\" xmlns=\"$3\" xmlns:xi=\"$4\">",
"<phpdoc:$1 xml:id=\"$6\" xmlns:phpdoc=\"$2\" xmlns=\"$3\" xmlns:xlink=\"$4\" xmlns:xi=\"$5\">",
"<phpdoc:$1 xml:id=\"$6\" xmlns:phpdoc=\"$5\" xmlns=\"$2\" xmlns:xlink=\"$3\" xmlns:xi=\"$4\">",
Expand Down