Skip to content

Commit ecf45e6

Browse files
MacFJAtheseer
authored andcommitted
Fix PHP7.2 object typehint (#354)
1 parent 61615ed commit ecf45e6

File tree

5 files changed

+98
-8
lines changed

5 files changed

+98
-8
lines changed

templates/html/components.xsl

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
<xsl:if test="@type">
326326
327327
<xsl:choose>
328-
<xsl:when test="@type = 'object'">
328+
<xsl:when test="@type = 'object' and pdx:type">
329329
<xsl:copy-of select="pdxf:link(pdx:type, '', pdx:type/@full)" />
330330
</xsl:when>
331331
<xsl:otherwise><xsl:value-of select="@type" /></xsl:otherwise>
@@ -504,7 +504,7 @@
504504
<xsl:template name="type">
505505
<xsl:param name="ctx" />
506506
<xsl:choose>
507-
<xsl:when test="$ctx/pdx:docblock/pdx:return/@type = 'object'"><xsl:value-of select="$ctx/pdx:docblock/pdx:return/pdx:type/@name" /></xsl:when>
507+
<xsl:when test="$ctx/pdx:docblock/pdx:return/@type = 'object' and $ctx/pdx:docblock/pdx:return/pdx:type/@name"><xsl:value-of select="$ctx/pdx:docblock/pdx:return/pdx:type/@name" /></xsl:when>
508508
<xsl:when test="not($ctx/pdx:docblock/pdx:return)">void</xsl:when>
509509
<xsl:otherwise><xsl:value-of select="$ctx/pdx:docblock/pdx:return/@type" /></xsl:otherwise>
510510
</xsl:choose>

templates/html/functions.xsl

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,19 @@
4747
<xsl:when test="$copy">
4848
<xsl:value-of select="$copy"/>
4949
</xsl:when>
50-
<xsl:otherwise>
50+
<xsl:when test="$ctx/@name">
5151
<xsl:value-of select="$ctx/@name"/>
52+
</xsl:when>
53+
<xsl:otherwise>
54+
<xsl:text>object</xsl:text>
5255
</xsl:otherwise>
5356
</xsl:choose>
5457
</xsl:variable>
5558

5659
<func:result>
60+
<xsl:value-of select="$ctx"/>
5761
<xsl:choose>
58-
<xsl:when test="$ctx/@unresolved = 'true'">
62+
<xsl:when test="$ctx/@unresolved = 'true' or not($ctx/@full)">
5963
<xsl:value-of select="$text"/>
6064
</xsl:when>
6165
<xsl:otherwise>

templates/html/synopsis.xsl

+5-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<xsl:for-each select="$unit/pdx:docblock/*[self::pdx:property or self::pdx:property-read or self::pdx:property-write]">
7878
<li>
7979
<i>magic<xsl:if test="local-name() = 'property-read'"> (r/o)</xsl:if><xsl:if test="local-name() = 'property-write'"> (w/o)</xsl:if></i>&#160;<xsl:choose>
80-
<xsl:when test="@type = 'object'">
80+
<xsl:when test="@type = 'object' and pdx:type/@name">
8181
<xsl:value-of select="pdx:type/@name" />
8282
</xsl:when>
8383
<xsl:when test="@type = '{unknown}'">
@@ -144,10 +144,11 @@
144144

145145
<xsl:template name="vartype">
146146
<xsl:choose>
147-
<xsl:when test="pdx:docblock/pdx:var/@type = 'object'">&#160;<span title="{pdx:docblock/pdx:var/pdx:type/@full}"><xsl:value-of select="pdx:docblock/pdx:var/pdx:type/@name" /></span></xsl:when>
147+
<xsl:when test="pdx:docblock/pdx:var/@type = 'object' and pdx:docblock/pdx:var/pdx:type">&#160;<span title="{pdx:docblock/pdx:var/pdx:type/@full}"><xsl:value-of select="pdx:docblock/pdx:var/pdx:type/@name" /></span></xsl:when>
148148
<xsl:when test="@type = '{unknown}'">
149149
<xsl:if test="pdx:docblock/pdx:var/@type">&#160;<xsl:value-of select="pdx:docblock/pdx:var/@type" /></xsl:if>
150150
</xsl:when>
151+
<xsl:when test="pdx:docblock/pdx:var/@type and not(@type)">&#160;<xsl:value-of select="pdx:docblock/pdx:var/@type" /></xsl:when>
151152
<xsl:otherwise>&#160;<xsl:value-of select="@type" /></xsl:otherwise>
152153
</xsl:choose>
153154
</xsl:template>
@@ -159,11 +160,11 @@
159160
<xsl:choose>
160161
<xsl:when test="pdx:return"><xsl:if test="pdx:return/@nullable = 'true'">?</xsl:if>
161162
<xsl:choose>
162-
<xsl:when test="pdx:return/@type = 'object'"><span title="{pdx:return/pdx:type/@name}"><xsl:value-of select="pdx:return/pdx:type/@name" /></span></xsl:when>
163+
<xsl:when test="pdx:return/@type = 'object' and pdx:return/pdx:type"><span title="{pdx:return/pdx:type/@name}"><xsl:value-of select="pdx:return/pdx:type/@name" /></span></xsl:when>
163164
<xsl:otherwise><xsl:value-of select="pdx:return/@type" /></xsl:otherwise>
164165
</xsl:choose>
165166
</xsl:when>
166-
<xsl:when test="pdx:docblock/pdx:return/@type = 'object'"><xsl:value-of select="pdx:docblock/pdx:return/pdx:type/@name" /></xsl:when>
167+
<xsl:when test="pdx:docblock/pdx:return/@type = 'object' and pdx:docblock/pdx:return/pdx:type"><xsl:value-of select="pdx:docblock/pdx:return/pdx:type/@name" /></xsl:when>
167168
<xsl:when test="not(pdx:docblock/pdx:return)">void</xsl:when>
168169
<xsl:otherwise><xsl:value-of select="pdx:docblock/pdx:return/@type" /></xsl:otherwise>
169170
</xsl:choose>

tests/data/issue354/src/test.php

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/**
4+
* Class Php72ObjectTypeClass
5+
*
6+
* @method object getObject()
7+
* @method \IteratorIterator getClassObject()
8+
*
9+
* @property object $magicObject
10+
* @property \SplStack $magicClassObject
11+
*/
12+
class Php72ObjectTypeClass {
13+
14+
/**
15+
* @var object
16+
*/
17+
public $object;
18+
19+
/**
20+
* @var \ArrayObject
21+
*/
22+
public $class;
23+
24+
function objectReturn(): object {
25+
return new stdClass();
26+
}
27+
28+
function objectParam(object $param) {}
29+
30+
/**
31+
* @param object $param
32+
*/
33+
function objectParamPhpDoc($param) {}
34+
35+
public function classParam(SplFileInfo $file) {}
36+
37+
/**
38+
* @param \SplFileInfo $file
39+
*/
40+
public function classParamPhpDoc($file) {}
41+
42+
/**
43+
* @return object
44+
*/
45+
public function objectReturnPhpDoc() {
46+
return new stdClass();
47+
}
48+
49+
function stringReturn(): string {
50+
return '';
51+
}
52+
53+
/**
54+
* @return string
55+
*/
56+
function stringReturnPhpDoc() {
57+
return '';
58+
}
59+
60+
function classReturn(): DateTime {
61+
return new DateTime();
62+
}
63+
64+
/**
65+
* @return \DateTime
66+
*/
67+
function classReturnPhpDoc() {
68+
return new DateTime();
69+
}
70+
}

tests/data/issue354/test.xml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<phpdox xmlns="http://xml.phpdox.net/config" silent="false">
3+
4+
<project name="phpDox-issue" source="${basedir}/src" workdir="${basedir}/xml">
5+
6+
<collector publiconly="false" backend="parser" />
7+
8+
<generator output="${basedir}/docs">
9+
<build engine="html" enabled="true" output="html" />
10+
<build engine="xml" enabled="true" output="xml" />
11+
</generator>
12+
13+
</project>
14+
15+
</phpdox>

0 commit comments

Comments
 (0)