Skip to content

Commit

Permalink
Improve type tag linking behaviour (#94)
Browse files Browse the repository at this point in the history
Also add proper support for void element and add a test case to the appropriate files.

---------

Co-authored-by: haszi <haszika80@gmail.com>
  • Loading branch information
haszi and haszi authored Feb 18, 2024
1 parent 27e3bc3 commit 45cffd6
Show file tree
Hide file tree
Showing 9 changed files with 762 additions and 70 deletions.
9 changes: 5 additions & 4 deletions phpdotnet/phd/Package/Generic/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,9 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML {
"modifier" => "public",
),
"methodsynopsis" => array(
"returntypes" => [],
"type_separator" => null,
"returntypes" => array(),
"type_separator" => array(),
"type_separator_stack" => array(),
),
"co" => 0,
"callouts" => 0,
Expand Down Expand Up @@ -1277,10 +1278,10 @@ public function format_parameter($open, $name, $attrs, $props)
}

public function format_void($open, $name, $attrs, $props) {
if ($props['sibling'] == 'methodname') {
if (isset($props['sibling']) && $props['sibling'] == 'methodname') {
return '(';
} else {
return '<span class="type"><span class="type void">void</span></span>';
return '<span class="type"><a href="language.types.void.html" class="type void">void</a></span>';
}
}

Expand Down
250 changes: 192 additions & 58 deletions phpdotnet/phd/Package/PHP/XHTML.php

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions tests/php/bug49102-1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,28 @@ 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">int</span> <code class="parameter">$mode</code></span>): <span class="type"><span class="type void">void</span></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.declarations.html#language.types.declarations.mixed" 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">int</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.declarations.html#language.types.declarations.mixed" 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">int</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.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$index</code></span>): <span class="type">bool</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>

<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::offsetGet</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$index</code></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="methodname"><strong>SplDoublyLinkedList::offsetGet</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.mixed.html" class="type mixed">mixed</a></span></div>

}</div>

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


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

<section>
<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 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>4. 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>
<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>
<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>
<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>
<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 intersection type parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type class="intersection"><type>Countable</type><type>Traversable</type></type><parameter>option</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>10. Constructor with DNF (Disjunctive Normal Form) type parameter</para>
<constructorsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <methodname>ClassName::__construct</methodname>
<methodparam><type class="union"><type class="intersection"><type>Countable</type><type>Traversable</type></type><type>DOMAttr</type></type><parameter>option</parameter></methodparam>
</constructorsynopsis>
</section>

<section>
<para>11. 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>
<methodparam><type>string</type><parameter>name</parameter></methodparam>
<methodparam><type>bool</type><parameter>isSomething</parameter></methodparam>
<methodparam><type>array</type><parameter>list</parameter></methodparam>
</constructorsynopsis>
</section>

</chapter>
86 changes: 86 additions & 0 deletions tests/php/data/type_rendering_methodsynopsis_parameters.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<chapter xml:id="type-rendering-methodsynopsis-parameters">

<section>
<para>1. Function/method with no parameters</para>
<methodsynopsis>
<methodname>function_name</methodname>
</methodsynopsis>
</section>

<section>
<para>2. Function/method with one parameter</para>
<methodsynopsis>
<methodname>function_name</methodname>
<methodparam><type>mixed</type><parameter>anything</parameter></methodparam>
</methodsynopsis>
</section>

<section>
<para>3. Function/method with optional parameter</para>
<methodsynopsis>
<methodname>function_name</methodname>
<methodparam choice="opt"><type>int</type><parameter>count</parameter><initializer>0</initializer></methodparam>
</methodsynopsis>
</section>

<section>
<para>4. Function/method with nullable parameter</para>
<methodsynopsis>
<methodname>function_name</methodname>
<methodparam><type class="union"><type>float</type><type>null</type></type><parameter>value</parameter></methodparam>
</methodsynopsis>
</section>

<section>
<para>5. Function/method with nullable optional parameter</para>
<methodsynopsis>
<methodname>function_name</methodname>
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>options</parameter><initializer>""</initializer></methodparam>
</methodsynopsis>
</section>

<section>
<para>6. Function/method with reference parameter</para>
<methodsynopsis>
<methodname>function_name</methodname>
<methodparam><type>array</type><parameter role="reference">reference</parameter></methodparam>
</methodsynopsis>
</section>

<section>
<para>7. Function/method with union type parameter</para>
<methodsynopsis>
<methodname>function_name</methodname>
<methodparam><type class="union"><type>iterable</type><type>resource</type><type>callable</type><type>null</type></type><parameter>option</parameter></methodparam>
</methodsynopsis>
</section>

<section>
<para>8. Function/method with intersection type parameter</para>
<methodsynopsis>
<methodname>function_name</methodname>
<methodparam><type class="intersection"><type>Countable</type><type>Traversable</type></type><parameter>option</parameter></methodparam>
</methodsynopsis>
</section>

<section>
<para>9. Function/method with DNF (Disjunctive Normal Form) type parameter</para>
<methodsynopsis>
<methodname>function_name</methodname>
<methodparam><type class="union"><type class="intersection"><type>Countable</type><type>Traversable</type></type><type>DOMAttr</type></type><parameter>option</parameter></methodparam>
</methodsynopsis>
</section>

<section>
<para>10. Function/method with more than three parameters</para>
<methodsynopsis>
<methodname>function_name</methodname>
<methodparam><type>int</type><parameter>count</parameter></methodparam>
<methodparam><type>string</type><parameter>name</parameter></methodparam>
<methodparam><type>bool</type><parameter>isSomething</parameter></methodparam>
<methodparam><type>array</type><parameter>list</parameter></methodparam>
</methodsynopsis>
</section>

</chapter>
75 changes: 75 additions & 0 deletions tests/php/data/type_rendering_methodsynopsis_return_types.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<chapter xml:id="type-rendering-methodsynopsis-return-types">

<section>
<para>1. Function/method with no return type</para>
<methodsynopsis>
<methodname>function_name</methodname>
</methodsynopsis>
</section>

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

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

<section>
<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>6. 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>
<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>
<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>
<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>
<methodsynopsis>
<type>stdClass</type><methodname>function_name</methodname>
</methodsynopsis>
</section>
-->
</chapter>
Loading

0 comments on commit 45cffd6

Please sign in to comment.