Skip to content

Commit 0b524a5

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix a few more classsynopsis generation issues
2 parents 7764d05 + 8168d31 commit 0b524a5

File tree

5 files changed

+69
-28
lines changed

5 files changed

+69
-28
lines changed

Zend/zend_exceptions.stub.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ public function getTraceAsString(): string;
2222

2323
class Exception implements Throwable
2424
{
25-
/** @var string Intentionally left untyped for BC reasons */
25+
/**
26+
* Intentionally left untyped for BC reasons
27+
* @var string
28+
*/
2629
protected $message = "";
2730
private string $string = "";
28-
/** @var int Intentionally left untyped for BC reasons */
31+
/**
32+
* Intentionally left untyped for BC reasons
33+
* @var int
34+
*/
2935
protected $code = 0;
3036
protected string $file = "";
3137
protected int $line = 0;
@@ -75,10 +81,16 @@ final public function getSeverity(): int {}
7581

7682
class Error implements Throwable
7783
{
78-
/** @var string Intentionally left untyped for BC reasons */
84+
/**
85+
* Intentionally left untyped for BC reasons
86+
* @var string
87+
*/
7988
protected $message = "";
8089
private string $string = "";
81-
/** @var int Intentionally left untyped for BC reasons */
90+
/**
91+
* Intentionally left untyped for BC reasons
92+
* @var int
93+
*/
8294
protected $code = 0;
8395
protected string $file = "";
8496
protected int $line;

Zend/zend_exceptions_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 48d8444730a0e1fbc5d81965733deb3d3c11e122 */
2+
* Stub hash: 9d1c2027ebd14e621d9b5b79056ba7300a455be8 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, IS_STRING, 0)
55
ZEND_END_ARG_INFO()

build/gen_stub.php

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,18 +1390,28 @@ class PropertyInfo
13901390
public $flags;
13911391
/** @var Type|null */
13921392
public $type;
1393+
/** @var Type|null */
1394+
public $phpDocType;
13931395
/** @var Expr|null */
13941396
public $defaultValue;
13951397
/** @var string|null */
13961398
public $defaultValueString;
13971399
/** @var bool */
13981400
public $isDocReadonly;
13991401

1400-
public function __construct(PropertyName $name, int $flags, ?Type $type, ?Expr $defaultValue, ?string $defaultValueString, bool $isDocReadonly)
1401-
{
1402+
public function __construct(
1403+
PropertyName $name,
1404+
int $flags,
1405+
?Type $type,
1406+
?Type $phpDocType,
1407+
?Expr $defaultValue,
1408+
?string $defaultValueString,
1409+
bool $isDocReadonly
1410+
) {
14021411
$this->name = $name;
14031412
$this->flags = $flags;
14041413
$this->type = $type;
1414+
$this->phpDocType = $phpDocType;
14051415
$this->defaultValue = $defaultValue;
14061416
$this->defaultValueString = $defaultValueString;
14071417
$this->isDocReadonly = $isDocReadonly;
@@ -1527,10 +1537,8 @@ public function getFieldSynopsisElement(DOMDocument $doc): DOMElement
15271537
$fieldsynopsisElement->appendChild($doc->createElement("modifier", "readonly"));
15281538
}
15291539

1530-
if ($this->type) {
1531-
$fieldsynopsisElement->appendChild(new DOMText("\n "));
1532-
$fieldsynopsisElement->appendChild($this->type->getTypeForDoc($doc));
1533-
}
1540+
$fieldsynopsisElement->appendChild(new DOMText("\n "));
1541+
$fieldsynopsisElement->appendChild($this->getFieldSynopsisType()->getTypeForDoc($doc));
15341542

15351543
$className = str_replace("\\", "-", $this->name->class->toLowerString());
15361544
$varnameElement = $doc->createElement("varname", $this->name->property);
@@ -1549,6 +1557,18 @@ public function getFieldSynopsisElement(DOMDocument $doc): DOMElement
15491557
return $fieldsynopsisElement;
15501558
}
15511559

1560+
private function getFieldSynopsisType(): Type {
1561+
if ($this->type) {
1562+
return $this->type;
1563+
}
1564+
1565+
if ($this->phpDocType) {
1566+
return $this->phpDocType;
1567+
}
1568+
1569+
throw new Exception("A property must have a type");
1570+
}
1571+
15521572
/** @return mixed */
15531573
private function evaluateDefaultValue(bool &$defaultValueConstant)
15541574
{
@@ -1813,7 +1833,7 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap): ?DOM
18131833

18141834
foreach ($this->extends as $k => $parent) {
18151835
$parentInfo = $classMap[$parent->toString()] ?? null;
1816-
if (!$parentInfo) {
1836+
if ($parentInfo === null) {
18171837
throw new Exception("Missing parent class " . $parent->toString());
18181838
}
18191839

@@ -1876,10 +1896,11 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap): ?DOM
18761896

18771897
foreach ($parentsWithInheritedProperties as $parent) {
18781898
$classSynopsis->appendChild(new DOMText("\n "));
1879-
$parentClassName = self::getClassSynopsisFilename($parent);
1899+
$parentReference = self::getClassSynopsisReference($parent);
1900+
18801901
$includeElement = $this->createIncludeElement(
18811902
$doc,
1882-
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.$parentClassName')/db:partintro/db:section/db:classsynopsis/db:fieldsynopsis[preceding-sibling::db:classsynopsisinfo[1][@role='comment' and text()='&Properties;']]))"
1903+
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$parentReference')/db:partintro/db:section/db:classsynopsis/db:fieldsynopsis[preceding-sibling::db:classsynopsisinfo[1][@role='comment' and text()='&Properties;']]))"
18831904
);
18841905
$classSynopsis->appendChild($includeElement);
18851906
}
@@ -1891,13 +1912,13 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap): ?DOM
18911912
$classSynopsisInfo->setAttribute("role", "comment");
18921913
$classSynopsis->appendChild($classSynopsisInfo);
18931914

1894-
$className = self::getClassSynopsisFilename($this->name);
1915+
$classReference = self::getClassSynopsisReference($this->name);
18951916

18961917
if ($this->hasConstructor()) {
18971918
$classSynopsis->appendChild(new DOMText("\n "));
18981919
$includeElement = $this->createIncludeElement(
18991920
$doc,
1900-
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.$className')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[not(@role='procedural')])"
1921+
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[not(@role='procedural')])"
19011922
);
19021923
$classSynopsis->appendChild($includeElement);
19031924
}
@@ -1906,7 +1927,7 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap): ?DOM
19061927
$classSynopsis->appendChild(new DOMText("\n "));
19071928
$includeElement = $this->createIncludeElement(
19081929
$doc,
1909-
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.$className')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])"
1930+
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[not(@role='procedural')])"
19101931
);
19111932
$classSynopsis->appendChild($includeElement);
19121933
}
@@ -1915,7 +1936,7 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap): ?DOM
19151936
$classSynopsis->appendChild(new DOMText("\n "));
19161937
$includeElement = $this->createIncludeElement(
19171938
$doc,
1918-
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.$className')/db:refentry/db:refsect1[@role='description']/descendant::db:destructorsynopsis[not(@role='procedural')])"
1939+
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:destructorsynopsis[not(@role='procedural')])"
19191940
);
19201941
$classSynopsis->appendChild($includeElement);
19211942
}
@@ -1929,10 +1950,10 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap): ?DOM
19291950

19301951
foreach ($parentsWithInheritedMethods as $parent) {
19311952
$classSynopsis->appendChild(new DOMText("\n "));
1932-
$parentClassName = self::getClassSynopsisFilename($parent);
1953+
$parentReference = self::getClassSynopsisReference($parent);
19331954
$includeElement = $this->createIncludeElement(
19341955
$doc,
1935-
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.$parentClassName')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])"
1956+
"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('$parentReference')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[not(@role='procedural')])"
19361957
);
19371958
$classSynopsis->appendChild($includeElement);
19381959
}
@@ -1987,6 +2008,10 @@ public static function getClassSynopsisFilename(Name $name): string {
19872008
return strtolower(implode('-', $name->parts));
19882009
}
19892010

2011+
public static function getClassSynopsisReference(Name $name): string {
2012+
return "class." . strtolower(implode('-', $name->parts));
2013+
}
2014+
19902015
/**
19912016
* @param Name[] $parentsWithInheritedProperties
19922017
* @param Name[] $parentsWithInheritedMethods
@@ -2146,15 +2171,15 @@ public function getType(): string {
21462171

21472172
if ($this->name === "param") {
21482173
preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)\s*\$\w+.*$/', $value, $matches);
2149-
} elseif ($this->name === "return") {
2150-
preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)(\s+|$)/', $value, $matches);
2174+
} elseif ($this->name === "return" || $this->name === "var") {
2175+
preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)/', $value, $matches);
21512176
}
21522177

21532178
if (!isset($matches[1])) {
21542179
throw new Exception("@$this->name doesn't contain a type or has an invalid format \"$value\"");
21552180
}
21562181

2157-
return $matches[1];
2182+
return trim($matches[1]);
21582183
}
21592184

21602185
public function getVariableName(): string {
@@ -2349,22 +2374,22 @@ function parseProperty(
23492374
?DocComment $comment,
23502375
PrettyPrinterAbstract $prettyPrinter
23512376
): PropertyInfo {
2352-
$docType = false;
2377+
$phpDocType = null;
23532378
$isDocReadonly = false;
23542379

23552380
if ($comment) {
23562381
$tags = parseDocComment($comment);
23572382
foreach ($tags as $tag) {
23582383
if ($tag->name === 'var') {
2359-
$docType = true;
2384+
$phpDocType = $tag->getType();
23602385
} elseif ($tag->name === 'readonly') {
23612386
$isDocReadonly = true;
23622387
}
23632388
}
23642389
}
23652390

23662391
$propertyType = $type ? Type::fromNode($type) : null;
2367-
if ($propertyType === null && !$docType) {
2392+
if ($propertyType === null && !$phpDocType) {
23682393
throw new Exception("Missing type for property $class::\$$property->name");
23692394
}
23702395

@@ -2383,6 +2408,7 @@ function parseProperty(
23832408
new PropertyName($class, $property->name->__toString()),
23842409
$flags,
23852410
$propertyType,
2411+
$phpDocType ? Type::fromString($phpDocType) : null,
23862412
$property->default,
23872413
$property->default ? $prettyPrinter->prettyPrintExpr($property->default) : null,
23882414
$isDocReadonly

ext/dom/php_dom.stub.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,10 @@ public function prepend(...$nodes): void {}
564564

565565
final class DOMException extends Exception
566566
{
567-
/** @var int Intentionally left untyped */
567+
/**
568+
* Intentionally left untyped for BC reasons
569+
* @var int
570+
*/
568571
public $code = 0;
569572
}
570573

ext/dom/php_dom_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: ccaa66ce5837d475f6231d1a1eadefa8e74db6b9 */
2+
* Stub hash: 74698bea9c5e0635cf91345e8512b9677489510c */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 0)
55
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)

0 commit comments

Comments
 (0)