Skip to content

Commit 3c3acc1

Browse files
committed
PHP 8.1 support
1 parent 160d18d commit 3c3acc1

File tree

8 files changed

+256
-223
lines changed

8 files changed

+256
-223
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"phpdocumentor/reflection-docblock": "^5.0",
1919
"gitonomy/gitlib": "^1.2",
2020
"cebe/markdown": "^1.2",
21-
"voku/simple_html_dom": "^4.7"
21+
"voku/simple_html_dom": "^4.7",
22+
"html2text/html2text": "^4.3"
2223
},
2324
"autoload": {
2425
"psr-4": {"PHPFUI\\InstaDoc\\": "src/PHPFUI/InstaDoc/"}

src/PHPFUI/InstaDoc/Controller.php

Lines changed: 13 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ public function display(array $classPagesToShow = Controller::VALID_CLASS_PAGES,
156156
$cell = new \PHPFUI\Cell();
157157
$div->add('   ');
158158
$icon = new \PHPFUI\FAIcon('far', 'clipboard');
159-
$parameters = $this->getMethodParameters($fullClassName);
159+
$parameters = $this->getConstructorParameters($fullClassName);
160+
$parameters = \str_replace("\n", '', $parameters);
160161
$hidden = new \PHPFUI\Input('text', 'clipboard', "new \\{$fullClassName}({$parameters});");
161162
$hidden->addClass('hide');
162163
$div->add($hidden);
@@ -455,7 +456,7 @@ public function getParameters() : array
455456
/**
456457
* Get parameters for the class and method
457458
*/
458-
public function getMethodParameters(string $className, $methodName = '__construct') : string
459+
public function getConstructorParameters(string $className) : string
459460
{
460461
try
461462
{
@@ -466,43 +467,24 @@ public function getMethodParameters(string $className, $methodName = '__construc
466467
return '';
467468
}
468469

470+
$methodName = '__construct';
471+
469472
if (! $reflection->hasMethod($methodName))
470473
{
471474
return '';
472475
}
473-
$method = $reflection->getMethod($methodName);
474-
475-
$info = '';
476-
$comma = '';
477-
478-
foreach ($method->getParameters() as $parameter)
479-
{
480-
$info .= $comma;
481-
$comma = ', ';
482476

483-
if ($parameter->hasType())
484-
{
485-
$type = $parameter->getType();
486-
$info .= $type->allowsNull() ? '?' : '';
487-
$info .= $type->getName();
488-
$info .= ' ';
489-
}
490-
$name = $parameter->getName();
491-
$info .= '$' . $name;
492-
493-
if ($parameter->isDefaultValueAvailable())
494-
{
495-
$value = $parameter->getDefaultValue();
496-
$info .= ' = ' . $this->getValueString($value);
497-
}
498-
}
477+
$method = $reflection->getMethod($methodName);
478+
$section = new \PHPFUI\InstaDoc\Section\CodeCommon($this, $className);
479+
$parameters = $section->getMethodParameters($method);
480+
$html2Text = new \Html2Text\Html2Text($parameters, ['do_links' => 'none']);
499481

500-
return $info;
482+
return $html2Text->getText();
501483
}
502484

503-
/**
504-
* Get a section for display. Override to change layout
505-
*/
485+
/**
486+
* Get a section for display. Override to change layout
487+
*/
506488
public function getSection(string $sectionName) : Section
507489
{
508490
if (! \in_array($sectionName, Controller::SECTIONS))
@@ -638,68 +620,4 @@ public function setParameters(array $parameters) : Controller
638620

639621
return $this;
640622
}
641-
642-
protected function getValueString($value) : string
643-
{
644-
switch (\gettype($value))
645-
{
646-
case 'array':
647-
$index = 0;
648-
$text = '[';
649-
$comma = '';
650-
651-
foreach ($value as $key => $part)
652-
{
653-
$text .= $comma;
654-
655-
if ($index !== $key)
656-
{
657-
$text .= $this->getValueString($key) . ' => ';
658-
}
659-
++$index;
660-
$text .= $this->getValueString($part);
661-
$comma = ', ';
662-
}
663-
$text .= ']';
664-
$value = $text;
665-
666-
break;
667-
668-
case 'string':
669-
$value = "'{$value}'";
670-
671-
break;
672-
673-
case 'object':
674-
$class = \get_class($value);
675-
676-
if ('ReflectionNamedType' == $class)
677-
{
678-
$value = ($value->allowsNull() ? '?' : '') . $value->getName();
679-
}
680-
else
681-
{
682-
$value = $class;
683-
}
684-
685-
break;
686-
687-
case 'resource':
688-
$value = 'resource';
689-
690-
break;
691-
692-
case 'boolean':
693-
$value = $value ? 'true' : 'false';
694-
695-
break;
696-
697-
case 'NULL':
698-
$value = 'NULL';
699-
700-
break;
701-
}
702-
703-
return $value;
704-
}
705623
}

0 commit comments

Comments
 (0)