@@ -1390,18 +1390,28 @@ class PropertyInfo
1390
1390
public $ flags ;
1391
1391
/** @var Type|null */
1392
1392
public $ type ;
1393
+ /** @var Type|null */
1394
+ public $ phpDocType ;
1393
1395
/** @var Expr|null */
1394
1396
public $ defaultValue ;
1395
1397
/** @var string|null */
1396
1398
public $ defaultValueString ;
1397
1399
/** @var bool */
1398
1400
public $ isDocReadonly ;
1399
1401
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
+ ) {
1402
1411
$ this ->name = $ name ;
1403
1412
$ this ->flags = $ flags ;
1404
1413
$ this ->type = $ type ;
1414
+ $ this ->phpDocType = $ phpDocType ;
1405
1415
$ this ->defaultValue = $ defaultValue ;
1406
1416
$ this ->defaultValueString = $ defaultValueString ;
1407
1417
$ this ->isDocReadonly = $ isDocReadonly ;
@@ -1527,10 +1537,8 @@ public function getFieldSynopsisElement(DOMDocument $doc): DOMElement
1527
1537
$ fieldsynopsisElement ->appendChild ($ doc ->createElement ("modifier " , "readonly " ));
1528
1538
}
1529
1539
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 ));
1534
1542
1535
1543
$ className = str_replace ("\\" , "- " , $ this ->name ->class ->toLowerString ());
1536
1544
$ varnameElement = $ doc ->createElement ("varname " , $ this ->name ->property );
@@ -1549,6 +1557,18 @@ public function getFieldSynopsisElement(DOMDocument $doc): DOMElement
1549
1557
return $ fieldsynopsisElement ;
1550
1558
}
1551
1559
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
+
1552
1572
/** @return mixed */
1553
1573
private function evaluateDefaultValue (bool &$ defaultValueConstant )
1554
1574
{
@@ -1813,7 +1833,7 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap): ?DOM
1813
1833
1814
1834
foreach ($ this ->extends as $ k => $ parent ) {
1815
1835
$ parentInfo = $ classMap [$ parent ->toString ()] ?? null ;
1816
- if (! $ parentInfo ) {
1836
+ if ($ parentInfo === null ) {
1817
1837
throw new Exception ("Missing parent class " . $ parent ->toString ());
1818
1838
}
1819
1839
@@ -1876,10 +1896,11 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap): ?DOM
1876
1896
1877
1897
foreach ($ parentsWithInheritedProperties as $ parent ) {
1878
1898
$ classSynopsis ->appendChild (new DOMText ("\n " ));
1879
- $ parentClassName = self ::getClassSynopsisFilename ($ parent );
1899
+ $ parentReference = self ::getClassSynopsisReference ($ parent );
1900
+
1880
1901
$ includeElement = $ this ->createIncludeElement (
1881
1902
$ 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;']])) "
1883
1904
);
1884
1905
$ classSynopsis ->appendChild ($ includeElement );
1885
1906
}
@@ -1891,13 +1912,13 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap): ?DOM
1891
1912
$ classSynopsisInfo ->setAttribute ("role " , "comment " );
1892
1913
$ classSynopsis ->appendChild ($ classSynopsisInfo );
1893
1914
1894
- $ className = self ::getClassSynopsisFilename ($ this ->name );
1915
+ $ classReference = self ::getClassSynopsisReference ($ this ->name );
1895
1916
1896
1917
if ($ this ->hasConstructor ()) {
1897
1918
$ classSynopsis ->appendChild (new DOMText ("\n " ));
1898
1919
$ includeElement = $ this ->createIncludeElement (
1899
1920
$ 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')]) "
1901
1922
);
1902
1923
$ classSynopsis ->appendChild ($ includeElement );
1903
1924
}
@@ -1906,7 +1927,7 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap): ?DOM
1906
1927
$ classSynopsis ->appendChild (new DOMText ("\n " ));
1907
1928
$ includeElement = $ this ->createIncludeElement (
1908
1929
$ 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') ]) "
1910
1931
);
1911
1932
$ classSynopsis ->appendChild ($ includeElement );
1912
1933
}
@@ -1915,7 +1936,7 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap): ?DOM
1915
1936
$ classSynopsis ->appendChild (new DOMText ("\n " ));
1916
1937
$ includeElement = $ this ->createIncludeElement (
1917
1938
$ 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')]) "
1919
1940
);
1920
1941
$ classSynopsis ->appendChild ($ includeElement );
1921
1942
}
@@ -1929,10 +1950,10 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap): ?DOM
1929
1950
1930
1951
foreach ($ parentsWithInheritedMethods as $ parent ) {
1931
1952
$ classSynopsis ->appendChild (new DOMText ("\n " ));
1932
- $ parentClassName = self ::getClassSynopsisFilename ($ parent );
1953
+ $ parentReference = self ::getClassSynopsisReference ($ parent );
1933
1954
$ includeElement = $ this ->createIncludeElement (
1934
1955
$ 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') ]) "
1936
1957
);
1937
1958
$ classSynopsis ->appendChild ($ includeElement );
1938
1959
}
@@ -1987,6 +2008,10 @@ public static function getClassSynopsisFilename(Name $name): string {
1987
2008
return strtolower (implode ('- ' , $ name ->parts ));
1988
2009
}
1989
2010
2011
+ public static function getClassSynopsisReference (Name $ name ): string {
2012
+ return "class. " . strtolower (implode ('- ' , $ name ->parts ));
2013
+ }
2014
+
1990
2015
/**
1991
2016
* @param Name[] $parentsWithInheritedProperties
1992
2017
* @param Name[] $parentsWithInheritedMethods
@@ -2146,15 +2171,15 @@ public function getType(): string {
2146
2171
2147
2172
if ($ this ->name === "param " ) {
2148
2173
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 );
2151
2176
}
2152
2177
2153
2178
if (!isset ($ matches [1 ])) {
2154
2179
throw new Exception ("@ $ this ->name doesn't contain a type or has an invalid format \"$ value \"" );
2155
2180
}
2156
2181
2157
- return $ matches [1 ];
2182
+ return trim ( $ matches [1 ]) ;
2158
2183
}
2159
2184
2160
2185
public function getVariableName (): string {
@@ -2349,22 +2374,22 @@ function parseProperty(
2349
2374
?DocComment $ comment ,
2350
2375
PrettyPrinterAbstract $ prettyPrinter
2351
2376
): PropertyInfo {
2352
- $ docType = false ;
2377
+ $ phpDocType = null ;
2353
2378
$ isDocReadonly = false ;
2354
2379
2355
2380
if ($ comment ) {
2356
2381
$ tags = parseDocComment ($ comment );
2357
2382
foreach ($ tags as $ tag ) {
2358
2383
if ($ tag ->name === 'var ' ) {
2359
- $ docType = true ;
2384
+ $ phpDocType = $ tag -> getType () ;
2360
2385
} elseif ($ tag ->name === 'readonly ' ) {
2361
2386
$ isDocReadonly = true ;
2362
2387
}
2363
2388
}
2364
2389
}
2365
2390
2366
2391
$ propertyType = $ type ? Type::fromNode ($ type ) : null ;
2367
- if ($ propertyType === null && !$ docType ) {
2392
+ if ($ propertyType === null && !$ phpDocType ) {
2368
2393
throw new Exception ("Missing type for property $ class:: \$$ property ->name " );
2369
2394
}
2370
2395
@@ -2383,6 +2408,7 @@ function parseProperty(
2383
2408
new PropertyName ($ class , $ property ->name ->__toString ()),
2384
2409
$ flags ,
2385
2410
$ propertyType ,
2411
+ $ phpDocType ? Type::fromString ($ phpDocType ) : null ,
2386
2412
$ property ->default ,
2387
2413
$ property ->default ? $ prettyPrinter ->prettyPrintExpr ($ property ->default ) : null ,
2388
2414
$ isDocReadonly
0 commit comments