Skip to content

Commit

Permalink
Add support for void element
Browse files Browse the repository at this point in the history
Add proper support for void element and add a test case to the approriate files.
  • Loading branch information
haszi committed Feb 12, 2024
1 parent cdc9480 commit 0ee0364
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 41 deletions.
1 change: 1 addition & 0 deletions phpdotnet/phd/Package/PHP/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ public function format_type_text($type, $tagname) {

public function format_void($open, $name, $attrs, $props) {
if (isset($props['sibling']) && $props['sibling'] == 'methodname') {
$this->cchunk["methodsynopsis"]["returntypes"][] = "void";
return '';
}
return parent::format_void($open, $name, $attrs, $props);
Expand Down
14 changes: 8 additions & 6 deletions tests/php/bug49102-1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ Content:

<div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div>
<div class="constructorsynopsis dc-description">
<span class="methodname"><strong>__construct</strong></span>()</div>
<span class="methodname"><strong>__construct</strong></span>(): <span class="type"><a href="language.types.void.html" class="type void">void</a></span></div>

<div class="methodsynopsis dc-description"><span class="methodname"><strong>setIteratorMode</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.html" class="type int">int</a></span> <code class="parameter">$mode</code></span>): <span class="type"><a href="language.types.void.html" class="type void">void</a></span></div>


<div class="classsynopsisinfo classsynopsisinfo_comment">/* Inherited methods */</div>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::bottom</strong></span>(): <span class="type"><a href="language.types.mixed.html" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::bottom</strong></span>(): <span class="type"><span class="type"><a href="language.types.mixed.html" class="type mixed">mixed</a></span><span class="type"><a href="language.types.void.html" class="type void">void</a></span></span></div>

<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::count</strong></span>(): <span class="type"><a href="language.types.integer.html" class="type int">int</a></span></div>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::count</strong></span>(): <span class="type"><span class="type"><a href="language.types.integer.html" class="type int">int</a></span><span class="type"><a href="language.types.void.html" class="type void">void</a></span></span></div>

<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::current</strong></span>(): <span class="type"><a href="language.types.mixed.html" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::current</strong></span>(): <span class="type"><span class="type"><a href="language.types.mixed.html" class="type mixed">mixed</a></span><span class="type"><a href="language.types.void.html" class="type void">void</a></span></span></div>

<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::getIteratorMode</strong></span>(): <span class="type"><a href="language.types.integer.html" class="type int">int</a></span></div>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::getIteratorMode</strong></span>(): <span class="type"><span class="type"><a href="language.types.integer.html" class="type int">int</a></span><span class="type"><a href="language.types.void.html" class="type void">void</a></span></span></div>

<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::offsetExists</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.html" class="type mixed">mixed</a></span> <code class="parameter">$index</code></span>): <span class="type"><a href="language.types.boolean.html" class="type bool">bool</a></span></div>

Expand All @@ -85,4 +85,6 @@ Content:

</div>
</div>
</div>
</div>


Original file line number Diff line number Diff line change
@@ -1,71 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<chapter xml:id="type-rendering-constructorsynopsis-parameters">
<chapter xml:id="type-rendering-constructorsynopsis-parameters-and-return-type">

<section>
<para>1. Constructor with no parameters</para>
<para>1. Constructor with no parameters, no return type</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <methodname>ClassName::__construct</methodname>
</constructorsynopsis>
</section>

<section>
<para>2. Constructor with one parameter</para>
<para>2. Constructor with no parameters, void (element) return type</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <methodname>ClassName::__construct</methodname>
<void/>
</constructorsynopsis>
</section>

<section>
<para>3. Constructor with one parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>private</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type>mixed</type><parameter>anything</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>3. Constructor with one parameter with whitespace in type tag</para>
<para>4. Constructor with one parameter with whitespace in type tag</para>
<constructorsynopsis>
<modifier>abstract</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type> bool </type><parameter>yesOrNo</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>4. Constructor with optional parameter</para>
<para>5. Constructor with optional parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>protected</modifier> <methodname>ClassName::__construct</methodname>
<methodparam choice="opt"><type>int</type><parameter>count</parameter><initializer>0</initializer></methodparam>
</constructorsynopsis>
</section>

<section>
<para>5. Constructor with nullable parameter</para>
<para>6. Constructor with nullable parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type class="union"><type>float</type><type>null</type></type><parameter>value</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>6. Constructor with nullable optional parameter</para>
<para>7. Constructor with nullable optional parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>private</modifier> <methodname>ClassName::__construct</methodname>
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>options</parameter><initializer>""</initializer></methodparam>
</constructorsynopsis>
</section>

<section>
<para>7. Constructor with reference parameter</para>
<para>8. Constructor with reference parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>protected</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type>array</type><parameter role="reference">reference</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>8. Constructor with union type parameter</para>
<para>9. Constructor with union type parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type class="union"><type>iterable</type><type>resource</type><type>callable</type><type>null</type></type><parameter>option</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>9. Constructor with more than three parameters</para>
<para>10. Constructor with more than three parameters</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>private</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type>int</type><parameter>count</parameter></methodparam>
Expand Down
22 changes: 15 additions & 7 deletions tests/php/data/type_rendering_methodsynopsis_return_types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,57 @@
</section>

<section>
<para>4. Function/method with one return type - mixed</para>
<para>4. Function/method with one return type - void element</para>
<methodsynopsis>
<methodname>function_name</methodname>
<void/>
</methodsynopsis>
</section>

<section>
<para>5. Function/method with one return type - mixed</para>
<methodsynopsis>
<type>mixed</type><methodname>function_name</methodname>
</methodsynopsis>
</section>

<section>
<para>5. Function/method with one return type with whitespace in type tag</para>
<para>6. Function/method with one return type with whitespace in type tag</para>
<methodsynopsis>
<type> bool </type><methodname>function_name</methodname>
</methodsynopsis>
</section>

<section>
<para>6. Function/method with union return type</para>
<para>7. Function/method with union return type</para>
<methodsynopsis>
<type class="union"><type>int</type><type>float</type><type>false</type></type><methodname>function_name</methodname>
</methodsynopsis>
</section>

<section>
<para>7. Function/method with nullable return type</para>
<para>8. Function/method with nullable return type</para>
<methodsynopsis>
<type class="union"><type>object</type><type>null</type></type><methodname>function_name</methodname>
</methodsynopsis>
</section>

<section>
<para>8. Function/method with nullable union return type</para>
<para>9. Function/method with nullable union return type</para>
<methodsynopsis>
<type class="union"><type>string</type><type>array</type><type>resource</type><type>callable</type><type>iterable</type><type>true</type><type>null</type></type><methodname>function_name</methodname>
</methodsynopsis>
</section>

<section>
<para>9. Function/method with unknown return type</para>
<para>10. Function/method with unknown return type</para>
<methodsynopsis>
<type>UnknownType</type><methodname>function_name</methodname>
</methodsynopsis>
</section>
<!-- TODO: fix known class return type - need to add a class to the index
<section role="description">
<para>10. Function/method with known class return type</para>
<para>11. Function/method with known class return type</para>
<methodsynopsis>
<type>stdClass</type><methodname>function_name</methodname>
</methodsynopsis>
Expand Down
18 changes: 12 additions & 6 deletions tests/php/type_rendering_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,43 @@ Content:
</div>

<div class="section">
<p class="para">4. Function/method with one return type - mixed</p>
<p class="para">4. Function/method with one return type - void element</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><a href="language.types.void.html" class="type void">void</a></span></div>

</div>

<div class="section">
<p class="para">5. Function/method with one return type - mixed</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><a href="language.types.mixed.html" class="type mixed">mixed</a></span></div>

</div>

<div class="section">
<p class="para">5. Function/method with one return type with whitespace in type tag</p>
<p class="para">6. Function/method with one return type with whitespace in type tag</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><a href="language.types.boolean.html" class="type bool">bool</a></span></div>

</div>

<div class="section">
<p class="para">6. Function/method with union return type</p>
<p class="para">7. Function/method with union return type</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><span class="type"><a href="language.types.integer.html" class="type int">int</a></span>|<span class="type"><a href="language.types.float.html" class="type float">float</a></span>|<span class="type"><a href="language.types.value.html" class="type false">false</a></span></span></div>

</div>

<div class="section">
<p class="para">7. Function/method with nullable return type</p>
<p class="para">8. Function/method with nullable return type</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><span class="type"><a href="language.types.null.html" class="type null">?</a></span><span class="type"><a href="language.types.object.html" class="type object">object</a></span></span></div>

</div>

<div class="section">
<p class="para">8. Function/method with nullable union return type</p>
<p class="para">9. Function/method with nullable union return type</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type"><span class="type"><a href="language.types.string.html" class="type string">string</a></span>|<span class="type"><a href="language.types.array.html" class="type array">array</a></span>|<span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>|<span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span>|<span class="type"><a href="language.types.iterable.html" class="type iterable">iterable</a></span>|<span class="type"><a href="language.types.value.html" class="type true">true</a></span>|<span class="type"><a href="language.types.null.html" class="type null">null</a></span></span></div>

</div>

<div class="section">
<p class="para">9. Function/method with unknown return type</p>
<p class="para">10. Function/method with unknown return type</p>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>function_name</strong></span>(): <span class="type">UnknownType</span></div>

</div>
Expand Down
Loading

0 comments on commit 0ee0364

Please sign in to comment.