Skip to content

Commit abd6e98

Browse files
MacFJAtheseer
authored andcommitted
Add variadic (...) support
- Update the collector to save the variadic information - Update the html rendering - Add test case (tests/data/issue344) Close #344
1 parent 4be0910 commit abd6e98

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

src/collector/backend/parser/UnitCollectingVisitor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ private function processMethodParams(MethodObject $method, array $params): void
324324
/** @var $param \PhpParser\Node\Param */
325325
$parameter = $method->addParameter($param->var->name);
326326
$parameter->setByReference($param->byRef);
327+
$parameter->setVariadic($param->variadic);
327328
$this->setVariableType($parameter, $param->type);
328329
$this->setVariableDefaultValue($parameter, $param->default);
329330
}

src/collector/project/AbstractVariableObject.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public function getType(): string {
8686
return $this->ctx->getAttribute('type');
8787
}
8888

89+
public function setVariadic($isVariadic): void {
90+
$this->ctx->setAttribute('variadic', $isVariadic ? 'true' : 'false');
91+
}
92+
8993
public function setNullable($isNullable): void {
9094
$this->ctx->setAttribute('nullable', $isNullable ? 'true' : 'false');
9195
}

templates/html/method.xsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
</xsl:when>
169169
<xsl:otherwise><xsl:value-of select="@type" /></xsl:otherwise>
170170
</xsl:choose>
171+
<xsl:if test="$param/@variadic = 'true'">[]</xsl:if>
171172
</dt>
172173
<dd><xsl:value-of select="$docparam/@description" />
173174
<xsl:if test="$docparam/text() != ''">
@@ -218,6 +219,7 @@
218219
</xsl:otherwise>
219220
</xsl:choose>
220221
<xsl:if test="$param/@byreference = 'true'">&amp;</xsl:if>
222+
<xsl:if test="$param/@variadic = 'true'">...</xsl:if>
221223
$<xsl:value-of select="$param/@name" />
222224
<xsl:if test="$param/@default"> = <xsl:choose>
223225
<xsl:when test="$param/@default = ''"><xsl:value-of select="$param/@constant" /></xsl:when>

tests/data/issue344/src/test.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
class VariadicClass {
4+
5+
function f(string ...$segments) {
6+
// ...
7+
}
8+
9+
}

tests/data/issue344/test.xml

Lines changed: 15 additions & 0 deletions
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)