From 1f50a42494ae4b881a4f5478b58bee71389ad3de Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Mon, 29 Apr 2024 18:51:08 -0400 Subject: [PATCH] Better enum support --- src/PHPFUI/InstaDoc/Section/CodeCommon.php | 14 +++++++++++++- src/PHPFUI/InstaDoc/Section/Doc.php | 10 ++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/PHPFUI/InstaDoc/Section/CodeCommon.php b/src/PHPFUI/InstaDoc/Section/CodeCommon.php index 5758b49..45f7505 100644 --- a/src/PHPFUI/InstaDoc/Section/CodeCommon.php +++ b/src/PHPFUI/InstaDoc/Section/CodeCommon.php @@ -127,7 +127,19 @@ public function getValueString(mixed $value) : string break; case 'object': - $value = $this->getClassName($value); + if (\enum_exists($value::class)) + { + $value = \property_exists($value, 'value') ? $value->value : ''; + + if ('string' == \gettype($value)) + { + $value = $this->getColor('string', "'{$value}'"); + } + } + else + { + $value = $this->getClassName($value); + } break; diff --git a/src/PHPFUI/InstaDoc/Section/Doc.php b/src/PHPFUI/InstaDoc/Section/Doc.php index 76b98cc..cf83c29 100644 --- a/src/PHPFUI/InstaDoc/Section/Doc.php +++ b/src/PHPFUI/InstaDoc/Section/Doc.php @@ -277,7 +277,7 @@ protected function getAccess(\ReflectionProperty|\ReflectionClassConstant $const if (\method_exists($constant, 'isReadOnly') && $constant->isReadOnly()) { - $type .= $this->getColor('keyword', 'readonly'); + $type .= ' ' . $this->getColor('keyword', 'readonly'); } return $type; @@ -290,7 +290,13 @@ protected function getConstant(\ReflectionClassConstant $constant, string $name, * $attributes = $this->getAttributes($constant); */ $docBlock = $this->getDocBlock($constant); - $info = $this->getAccess($constant) . ' ' . $this->getColor('constant', $this->getColor('constant', $this->getName($constant, $name, true))) . ' = ' . $this->getValueString($value); + $info = $this->getAccess($constant) . ' ' . $this->getColor('constant', $this->getColor('constant', $this->getName($constant, $name, true))); + $valueString = $this->getValueString($value); + + if (\strlen($valueString)) + { + $info .= ' = ' . $valueString; + } $info .= $this->getComments($docBlock); return $info;