Skip to content

Commit

Permalink
Improve phpdomain templates (#45)
Browse files Browse the repository at this point in the history
* [BUGFIX] Remove duplicate colon after "Returns"

* [TASK] Extract display of vendor from component name

* [TASK] Use partial includes for method names and FQNs

* [TASK] Use partial includes for method names and FQNs
  • Loading branch information
linawolf authored May 15, 2024
1 parent 91219d4 commit 6a7f45d
Show file tree
Hide file tree
Showing 59 changed files with 426 additions and 153 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,3 @@ jobs:
run: "make code-style"
- name: "Run static code analysis"
run: "make phpstan"
- name: "Run rector"
run: "make rector-dry"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ test-unit: ## Runs unit tests with phpunit
vendor/bin/phpunit --testsuite=unit

.PHONY: test
test: test-integration test-unit ## Runs all test suites with phpunit
test: fix-code-style phpstan test-integration test-unit ## Runs all test suites with phpunit
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ parameters:
ignoreErrors:
-
message: "#^Function phpDocumentor\\\\Guides\\\\DependencyInjection\\\\template not found\\.$#"
count: 11
count: 9
path: src/DependencyInjection/GuidesPhpDomainExtension.php

-
Expand Down
14 changes: 13 additions & 1 deletion resources/template/html/body/directive/php/component.html.twig
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
{%- if node.name.namespaceNode %}{%- set fqn = '\\' ~ node.name.namespaceNode.name ~ '\\' ~ node.name.namespaceNode.name -%}{% endif -%}
<dl class="php {{ node.type }}">
<dt class="sig sig-object php"
{%- if not node.noindex %} id="{{ node.id }}"{% endif -%}>
{% for modifier in node.modifiers -%}
{{- renderNode(modifier) }}{{ ' ' -}}
{%- endfor -%}
<em class="property"><span class="pre">{{ node.type }}</span> </em>
{{ renderNode(node.name) }} {%- if node.type == 'enum' and node.phpType -%}<span class="pre"> : {{ node.phpType }}</span> {% endif -%}
{% include "body/directive/php/partials/fullyQualifiedName.html.twig" with {'className': node.name, 'fqn': fqn} %}
{%- if node.type == 'enum' and node.phpType -%}<span class="pre"> : {{ node.phpType }}</span> {% endif -%}
{% include "body/directive/php/partials/linkToSnippet.html.twig" %}
</dt>
<dd>
{% if node.name.namespaceNode %}
<dl class="field-list simple">
{% if node.name.namespaceNode %}
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
{% include "body/directive/php/partials/codeStyle.html.twig" with {'code': fqn} %}
</dd>
{% endif -%}
</dl>
{% endif -%}
{{ renderNode(node.value) }}
</dd>
</dl>

This file was deleted.

4 changes: 2 additions & 2 deletions resources/template/html/body/directive/php/method.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
{%- for modifier in node.modifiers -%}
{{- renderNode(modifier) }}{{ ' ' -}}
{%- endfor -%}
{{- renderNode(node.methodName) -}}
{% include "body/directive/php/partials/method/methodName.html.twig" with {'methodName': node.methodName} %}
{% include "body/directive/php/partials/linkToSnippet.html.twig" %}
</dt>
<dd>
{{ renderNode(node.value) }}
{% if node.returnsDescription %}
<dl class="field-list simple">
<dt class="field-even">Returns:</dt>
<dt class="field-even">Returns</dt>
<dd class="field-even">
{{ renderNode(node.returnsDescription) }}
</dd>
Expand Down
11 changes: 0 additions & 11 deletions resources/template/html/body/directive/php/methodName.html.twig

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span class="pre">{{ code|raw }}</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<span class="sig-name descname">
<span class="pre fqn"
{%- if fqn %} data-fqn="{{ fqn }}" title="{{ fqn }}"{% endif %}>
{{- className.name -}}
</span>
</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

<span class="sig-name descname">
{%- for modifier in methodName.modifiers -%}
<span class="pre php-modifier">{{- renderNode(modifier) }}{{ ' ' -}}</span>
{%- endfor -%}
<span class="pre">{{ methodName.name }}</span></span>
<span class="sig-paren">(</span>
{% for param in methodName.params -%}
<em class="sig-param"><span class="pre">{{ param }}</span></em>
{%- if not loop.last %}, {% endif -%}
{%- endfor %}
<span class="sig-paren">)</span>
{% if methodName.return %}
<em class="sig-returns"><span class="pre">: {{ methodName.return }}</span></em>
{% endif %}
4 changes: 0 additions & 4 deletions src/DependencyInjection/GuidesPhpDomainExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use T3Docs\GuidesPhpDomain\Nodes\FullyQualifiedNameNode;
use T3Docs\GuidesPhpDomain\Nodes\MemberNameNode;
use T3Docs\GuidesPhpDomain\Nodes\MethodNameNode;
use T3Docs\GuidesPhpDomain\Nodes\PhpCaseNode;
use T3Docs\GuidesPhpDomain\Nodes\PhpComponentNode;
use T3Docs\GuidesPhpDomain\Nodes\PhpConstNode;
Expand Down Expand Up @@ -44,7 +42,6 @@ public function prepend(ContainerBuilder $container): void
[
'base_template_paths' => [dirname(__DIR__, 2) . '/resources/template/html'],
'templates' => [
template(FullyQualifiedNameNode::class, 'body/directive/php/fullyQualifiedName.html.twig'),
template(PhpCaseNode::class, 'body/directive/php/case.html.twig'),
template(PhpComponentNode::class, 'body/directive/php/component.html.twig'),
template(PhpConstNode::class, 'body/directive/php/const.html.twig'),
Expand All @@ -54,7 +51,6 @@ public function prepend(ContainerBuilder $container): void
template(PhpPropertyNode::class, 'body/directive/php/property.html.twig'),
template(PhpModifierNode::class, 'body/directive/php/modifier.html.twig'),
template(MemberNameNode::class, 'body/directive/php/memberName.html.twig'),
template(MethodNameNode::class, 'body/directive/php/methodName.html.twig'),
],
],
);
Expand Down
10 changes: 8 additions & 2 deletions tests/integration/class-abstract/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ <h1>abstract class</h1>
<dl class="php class">
<dt class="sig sig-object php" id="typo3-cms-core-abstracttest">
<span class="sig-name modifier"><span class="pre">abstract</span></span> <em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">AbstractTest</span></span> <a class="headerlink" href="#typo3-cms-core-abstracttest" title="Permalink to this definition"></a>
<span class="sig-name descname">
<span class="pre fqn" data-fqn="\TYPO3\CMS\Core\TYPO3\CMS\Core" title="\TYPO3\CMS\Core\TYPO3\CMS\Core">AbstractTest</span>
</span> <a class="headerlink" href="#typo3-cms-core-abstracttest" title="Permalink to this definition"></a>
</dt>
<dd>
<dl class="field-list simple">
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
<span class="pre">\TYPO3\CMS\Core\TYPO3\CMS\Core</span> </dd>
</dl>

<p>Lorem Ipsum Dolor!</p>

Expand Down
10 changes: 8 additions & 2 deletions tests/integration/class-duplicate/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ <h1>final class</h1>
<dl class="php class">
<dt class="sig sig-object php" id="typo3-cms-core-test">
<span class="sig-name modifier"><span class="pre">final</span></span> <em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">Test</span></span> <a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition"></a>
<span class="sig-name descname">
<span class="pre fqn" data-fqn="\TYPO3\CMS\Core\TYPO3\CMS\Core" title="\TYPO3\CMS\Core\TYPO3\CMS\Core">Test</span>
</span> <a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition"></a>
</dt>
<dd>
<dl class="field-list simple">
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
<span class="pre">\TYPO3\CMS\Core\TYPO3\CMS\Core</span> </dd>
</dl>

<p>Lorem Ipsum Dolor!</p>

Expand Down
10 changes: 8 additions & 2 deletions tests/integration/class-final-abstract/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ <h1>abstract final class causes warning</h1>
<dl class="php class">
<dt class="sig sig-object php" id="typo3-cms-core-test">
<span class="sig-name modifier"><span class="pre">abstract</span></span> <span class="sig-name modifier"><span class="pre">final</span></span> <em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">Test</span></span> <a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition"></a>
<span class="sig-name descname">
<span class="pre fqn" data-fqn="\TYPO3\CMS\Core\TYPO3\CMS\Core" title="\TYPO3\CMS\Core\TYPO3\CMS\Core">Test</span>
</span> <a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition"></a>
</dt>
<dd>
<dl class="field-list simple">
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
<span class="pre">\TYPO3\CMS\Core\TYPO3\CMS\Core</span> </dd>
</dl>

<p>Lorem Ipsum Dolor!</p>

Expand Down
10 changes: 8 additions & 2 deletions tests/integration/class-final/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ <h1>final class</h1>
<dl class="php class">
<dt class="sig sig-object php" id="typo3-cms-core-test">
<span class="sig-name modifier"><span class="pre">final</span></span> <em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">Test</span></span> <a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition"></a>
<span class="sig-name descname">
<span class="pre fqn" data-fqn="\TYPO3\CMS\Core\TYPO3\CMS\Core" title="\TYPO3\CMS\Core\TYPO3\CMS\Core">Test</span>
</span> <a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition"></a>
</dt>
<dd>
<dl class="field-list simple">
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
<span class="pre">\TYPO3\CMS\Core\TYPO3\CMS\Core</span> </dd>
</dl>

<p>Lorem Ipsum Dolor!</p>

Expand Down
30 changes: 24 additions & 6 deletions tests/integration/class-namespace-directive/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ <h1>PHP Class with current namespace from directive</h1>
<dl class="php class">
<dt class="sig sig-object php" id="typo3-cms-core-testclass">
<em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">TestClass</span></span> <a class="headerlink" href="#typo3-cms-core-testclass" title="Permalink to this definition"></a>
<span class="sig-name descname">
<span class="pre fqn" data-fqn="\TYPO3\CMS\Core\TYPO3\CMS\Core" title="\TYPO3\CMS\Core\TYPO3\CMS\Core">TestClass</span>
</span> <a class="headerlink" href="#typo3-cms-core-testclass" title="Permalink to this definition"></a>
</dt>
<dd>
<dl class="field-list simple">
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
<span class="pre">\TYPO3\CMS\Core\TYPO3\CMS\Core</span> </dd>
</dl>

<p>Lorem Ipsum Dolor!</p>

Expand All @@ -16,10 +22,16 @@ <h1>PHP Class with current namespace from directive</h1>
<dl class="php class">
<dt class="sig sig-object php" id="typo3-cms-core-anotherclass">
<em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">AnotherClass</span></span> <a class="headerlink" href="#typo3-cms-core-anotherclass" title="Permalink to this definition"></a>
<span class="sig-name descname">
<span class="pre fqn" data-fqn="\TYPO3\CMS\Core\TYPO3\CMS\Core" title="\TYPO3\CMS\Core\TYPO3\CMS\Core">AnotherClass</span>
</span> <a class="headerlink" href="#typo3-cms-core-anotherclass" title="Permalink to this definition"></a>
</dt>
<dd>
<dl class="field-list simple">
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
<span class="pre">\TYPO3\CMS\Core\TYPO3\CMS\Core</span> </dd>
</dl>

<p>Lorem Ipsum Dolor Another!</p>

Expand All @@ -28,10 +40,16 @@ <h1>PHP Class with current namespace from directive</h1>
<dl class="php class">
<dt class="sig sig-object php" id="myvendor-some-namespace-anotherclass">
<em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\MyVendor\Some\Namespace\</span></span>
<span class="sig-name descname"><span class="pre">AnotherClass</span></span> <a class="headerlink" href="#myvendor-some-namespace-anotherclass" title="Permalink to this definition"></a>
<span class="sig-name descname">
<span class="pre fqn" data-fqn="\MyVendor\Some\Namespace\MyVendor\Some\Namespace" title="\MyVendor\Some\Namespace\MyVendor\Some\Namespace">AnotherClass</span>
</span> <a class="headerlink" href="#myvendor-some-namespace-anotherclass" title="Permalink to this definition"></a>
</dt>
<dd>
<dl class="field-list simple">
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
<span class="pre">\MyVendor\Some\Namespace\MyVendor\Some\Namespace</span> </dd>
</dl>

<p>Lorem Ipsum Dolor Yet Another!</p>

Expand Down
10 changes: 8 additions & 2 deletions tests/integration/class-twice-noindex/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ <h1>class listed twice throws warning</h1>
<dl class="php class">
<dt class="sig sig-object php" id="typo3-cms-core-test">
<em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">Test</span></span> <a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition"></a>
<span class="sig-name descname">
<span class="pre fqn" data-fqn="\TYPO3\CMS\Core\TYPO3\CMS\Core" title="\TYPO3\CMS\Core\TYPO3\CMS\Core">Test</span>
</span> <a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition"></a>
</dt>
<dd>
<dl class="field-list simple">
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
<span class="pre">\TYPO3\CMS\Core\TYPO3\CMS\Core</span> </dd>
</dl>

<p>Lorem Ipsum Dolor!</p>

Expand Down
10 changes: 8 additions & 2 deletions tests/integration/class-twice-noindex/expected/page2.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ <h1>class listed twice throws warning</h1>
<dl class="php class">
<dt class="sig sig-object php">
<em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">Test</span></span> </dt>
<span class="sig-name descname">
<span class="pre fqn" data-fqn="\TYPO3\CMS\Core\TYPO3\CMS\Core" title="\TYPO3\CMS\Core\TYPO3\CMS\Core">Test</span>
</span> </dt>
<dd>
<dl class="field-list simple">
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
<span class="pre">\TYPO3\CMS\Core\TYPO3\CMS\Core</span> </dd>
</dl>

<p>Lorem Ipsum Dolor!</p>

Expand Down
10 changes: 8 additions & 2 deletions tests/integration/class-twice-warning/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ <h1>class listed twice throws warning</h1>
<dl class="php class">
<dt class="sig sig-object php" id="typo3-cms-core-test">
<em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">Test</span></span> <a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition"></a>
<span class="sig-name descname">
<span class="pre fqn" data-fqn="\TYPO3\CMS\Core\TYPO3\CMS\Core" title="\TYPO3\CMS\Core\TYPO3\CMS\Core">Test</span>
</span> <a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition"></a>
</dt>
<dd>
<dl class="field-list simple">
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
<span class="pre">\TYPO3\CMS\Core\TYPO3\CMS\Core</span> </dd>
</dl>

<p>Lorem Ipsum Dolor!</p>

Expand Down
10 changes: 8 additions & 2 deletions tests/integration/class-twice-warning/expected/page2.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ <h1>class listed twice throws warning</h1>
<dl class="php class">
<dt class="sig sig-object php" id="typo3-cms-core-test">
<em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">Test</span></span> <a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition"></a>
<span class="sig-name descname">
<span class="pre fqn" data-fqn="\TYPO3\CMS\Core\TYPO3\CMS\Core" title="\TYPO3\CMS\Core\TYPO3\CMS\Core">Test</span>
</span> <a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition"></a>
</dt>
<dd>
<dl class="field-list simple">
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
<span class="pre">\TYPO3\CMS\Core\TYPO3\CMS\Core</span> </dd>
</dl>

<p>Lorem Ipsum Dolor!</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ <h1>PHP class with constants</h1>
<dl class="php class">
<dt class="sig sig-object php" id="chucklefactory-funclass">
<em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\ChuckleFactory\</span></span>
<span class="sig-name descname"><span class="pre">FunClass</span></span> <a class="headerlink" href="#chucklefactory-funclass" title="Permalink to this definition"></a>
<span class="sig-name descname">
<span class="pre fqn" data-fqn="\ChuckleFactory\ChuckleFactory" title="\ChuckleFactory\ChuckleFactory">FunClass</span>
</span> <a class="headerlink" href="#chucklefactory-funclass" title="Permalink to this definition"></a>
</dt>
<dd>
<dl class="field-list simple">
<dt class="field-even">Fully qualified name</dt>
<dd class="field-even">
<span class="pre">\ChuckleFactory\ChuckleFactory</span> </dd>
</dl>

<p>Where Fun Knows No Bounds!</p>
<dl class="php const">
Expand Down
Loading

0 comments on commit 6a7f45d

Please sign in to comment.