Skip to content

Commit 79d2e34

Browse files
committed
Traits support
1 parent ae1943a commit 79d2e34

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ But with PHPFUI\InstaDoc, you can document your site in about a minute (OK, mayb
2828
* 5+ line config compatible with all PHP frameworks, or standalone
2929
* Uses [Foundation CSS framework](https://get.foundation) for a great experience on mobile
3030

31-
### Install PHPFUI\InstaDoc
31+
### Install PHPFUI\InstaDoc (requires PHP >= 7.2)
3232
composer require phpfui/InstaDoc
3333

3434
### Run Installation Script

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=7.1",
15+
"php": ">=7.2",
1616
"phpfui/phpfui": "^6.0",
1717
"scrivo/highlight.php": ">=9.17",
1818
"phpdocumentor/reflection-docblock": ">=3.0",

src/PHPFUI/InstaDoc/Section/Doc.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public function generate(\PHPFUI\Instadoc\PageInterface $page, string $fullClass
104104
$accordion->addTab('Extends', $table);
105105
}
106106

107-
108107
$table = new \PHPFUI\Table();
109108
$table->addClass('hover');
110109
$table->addClass('unstriped');
@@ -130,7 +129,6 @@ public function generate(\PHPFUI\Instadoc\PageInterface $page, string $fullClass
130129

131130
foreach ($interfaces as $interface)
132131
{
133-
$class = $interface->getName();
134132
$table->addRow([$this->getClassName($interface->getName())]);
135133
}
136134

@@ -140,6 +138,26 @@ public function generate(\PHPFUI\Instadoc\PageInterface $page, string $fullClass
140138
}
141139
}
142140

141+
$traits = $this->getTraits($this->reflection);
142+
143+
if ($traits)
144+
{
145+
ksort($traits, SORT_FLAG_CASE | SORT_STRING);
146+
$table = new \PHPFUI\Table();
147+
$table->addClass('hover');
148+
$table->addClass('unstriped');
149+
150+
foreach ($traits as $trait)
151+
{
152+
$table->addRow([$this->getClassName($trait->getName())]);
153+
}
154+
155+
if (count($table))
156+
{
157+
$accordion->addTab('Traits', $table);
158+
}
159+
}
160+
143161
if (count($accordion))
144162
{
145163
$container->add($accordion);
@@ -414,4 +432,21 @@ protected function objectSort(array &$objects) : void
414432
{
415433
usort($objects, [$this, 'objectCompare']);
416434
}
435+
436+
/**
437+
* return traits for the entire inheritance tree, not just the current class
438+
*/
439+
private function getTraits(\ReflectionClass $reflection) : array
440+
{
441+
$traits = [];
442+
443+
$parent = $reflection->getParentClass();
444+
445+
if ($parent)
446+
{
447+
$traits = $this->getTraits($parent);
448+
}
449+
450+
return array_merge($traits, $reflection->getTraits());
451+
}
417452
}

0 commit comments

Comments
 (0)