Skip to content
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

Add support for @property / @property-read / @property-write #357

Merged
merged 1 commit into from
May 10, 2019
Merged
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions src/docblock/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ class Factory {
'invalid' => 'TheSeer\\phpDox\\DocBlock\\InvalidParser',
'generic' => 'TheSeer\\phpDox\\DocBlock\\GenericParser',

'description' => 'TheSeer\\phpDox\\DocBlock\\DescriptionParser',
'param' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
'var' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
'return' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
'throws' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
'license' => 'TheSeer\\phpDox\\DocBlock\\LicenseParser',
'description' => 'TheSeer\\phpDox\\DocBlock\\DescriptionParser',
'param' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
'property-read' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
'property-write' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
'property' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
'var' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
'return' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
'throws' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
'license' => 'TheSeer\\phpDox\\DocBlock\\LicenseParser',

'internal' => 'TheSeer\\phpDox\\DocBlock\\InternalParser',
'inheritdoc' => 'TheSeer\\phpDox\\DocBlock\\InheritdocParser'
Expand Down
2 changes: 1 addition & 1 deletion src/docblock/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function parse($block, array $aliasMap) {
}
$buffer = [];

\preg_match('/^\@([a-zA-Z0-9_]+)(.*)$/', $line, $lineParts);
\preg_match('/^\@([a-zA-Z0-9_-]+)(.*)$/', $line, $lineParts);
$name = ($lineParts[1] ?? '(undefined)');
$payload = (isset($lineParts[2]) ? \trim($lineParts[2]) : '');

Expand Down
50 changes: 50 additions & 0 deletions templates/html/components.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,61 @@
</xsl:for-each>
</ul>
</xsl:if>
<xsl:if test="//pdx:docblock/pdx:property">
<h4>magic</h4>
<ul class="members">
<xsl:for-each select="//pdx:docblock/pdx:property">
<xsl:sort select="@variable" />
<xsl:call-template name="magicmemberli" />
</xsl:for-each>
</ul>
</xsl:if>
<xsl:if test="//pdx:docblock/pdx:property-read">
<h4>magic — Read only</h4>
<ul class="members">
<xsl:for-each select="//pdx:docblock/pdx:property-read">
<xsl:sort select="@variable" />
<xsl:call-template name="magicmemberli" />
</xsl:for-each>
</ul>
</xsl:if>
<xsl:if test="//pdx:docblock/pdx:property-write">
<h4>magic — Write only</h4>
<ul class="members">
<xsl:for-each select="//pdx:docblock/pdx:property-write">
<xsl:sort select="@variable" />
<xsl:call-template name="magicmemberli" />
</xsl:for-each>
</ul>
</xsl:if>
</div>
</xsl:template>

<!-- ######################################################################################################### -->

<xsl:template name="magicmemberli">
<li id="{@variable}">
<strong><xsl:value-of select="@variable" /></strong>
<xsl:if test="@type">
<xsl:choose>
<xsl:when test="@type = 'object'">
<xsl:copy-of select="pdxf:link(pdx:type, '', pdx:type/@full)" />
</xsl:when>
<xsl:otherwise><xsl:value-of select="@type" /></xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="@description != ''">
<br/>
<span class="indent">
<xsl:value-of select="@description" />
</span>
</xsl:if>
</li>
</xsl:template>

<!-- ######################################################################################################### -->

<xsl:template name="memberli">
<li id="{@name}">
<strong>$<xsl:value-of select="@name" /></strong>
Expand Down
15 changes: 15 additions & 0 deletions templates/html/synopsis.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@
</xsl:choose></xsl:if>;
</li>
</xsl:for-each>
<xsl:for-each select="$unit/pdx:docblock/*[self::pdx:property or self::pdx:property-read or self::pdx:property-write]">
<li>
<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>
<xsl:when test="@type = 'object'">
<xsl:value-of select="pdx:type/@name" />
</xsl:when>
<xsl:when test="@type = '{unknown}'">
<xsl:text>object</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@type" />
</xsl:otherwise>
</xsl:choose>&#160;<a href="#members"><xsl:value-of select="@variable" /></a>;
</li>
</xsl:for-each>
</ul>
</xsl:if>

Expand Down
13 changes: 8 additions & 5 deletions tests/Integration/docblock/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ public static function getInstanceMapDataprovider() {
'invalid' => 'TheSeer\\phpDox\\DocBlock\\InvalidParser',
'generic' => 'TheSeer\\phpDox\\DocBlock\\GenericParser',

'description' => 'TheSeer\\phpDox\\DocBlock\\DescriptionParser',
'param' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
'var' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
'return' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
'license' => 'TheSeer\\phpDox\\DocBlock\\LicenseParser',
'description' => 'TheSeer\\phpDox\\DocBlock\\DescriptionParser',
'param' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
'property-read' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
'property-write' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
'property' => 'TheSeer\\phpDox\\DocBlock\\ParamParser',
'var' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
'return' => 'TheSeer\\phpDox\\DocBlock\\VarParser',
'license' => 'TheSeer\\phpDox\\DocBlock\\LicenseParser',

'internal' => 'TheSeer\\phpDox\\DocBlock\\InternalParser'
];
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/docblock/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function docblockSources() {
['param_without_description'],
['param_without_varname'],
['param_without_varname_and_description'],
['property'],
['see'],
['since'],
['throws'],
Expand Down
5 changes: 5 additions & 0 deletions tests/data/docbock/property
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* @property int $state The class state
* @property-read int $pastState The previous class state
* @property-write int $call The number or call
*/
1 change: 1 addition & 0 deletions tests/data/docbock/property.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<docblock xmlns="http://xml.phpdox.net/src"><description/><property type="int" variable="$state" description="The class state"/><property-read description="The previous class state" type="int" variable="$pastState"/><property-write description="The number or call" type="int" variable="$call"/></docblock>