@@ -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
0 commit comments