Skip to content

Commit 1f50a42

Browse files
committed
Better enum support
1 parent 29c0261 commit 1f50a42

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/PHPFUI/InstaDoc/Section/CodeCommon.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,19 @@ public function getValueString(mixed $value) : string
127127
break;
128128

129129
case 'object':
130-
$value = $this->getClassName($value);
130+
if (\enum_exists($value::class))
131+
{
132+
$value = \property_exists($value, 'value') ? $value->value : '';
133+
134+
if ('string' == \gettype($value))
135+
{
136+
$value = $this->getColor('string', "'{$value}'");
137+
}
138+
}
139+
else
140+
{
141+
$value = $this->getClassName($value);
142+
}
131143

132144
break;
133145

src/PHPFUI/InstaDoc/Section/Doc.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ protected function getAccess(\ReflectionProperty|\ReflectionClassConstant $const
277277

278278
if (\method_exists($constant, 'isReadOnly') && $constant->isReadOnly())
279279
{
280-
$type .= $this->getColor('keyword', 'readonly');
280+
$type .= ' ' . $this->getColor('keyword', 'readonly');
281281
}
282282

283283
return $type;
@@ -290,7 +290,13 @@ protected function getConstant(\ReflectionClassConstant $constant, string $name,
290290
* $attributes = $this->getAttributes($constant);
291291
*/
292292
$docBlock = $this->getDocBlock($constant);
293-
$info = $this->getAccess($constant) . ' ' . $this->getColor('constant', $this->getColor('constant', $this->getName($constant, $name, true))) . ' = ' . $this->getValueString($value);
293+
$info = $this->getAccess($constant) . ' ' . $this->getColor('constant', $this->getColor('constant', $this->getName($constant, $name, true)));
294+
$valueString = $this->getValueString($value);
295+
296+
if (\strlen($valueString))
297+
{
298+
$info .= ' = ' . $valueString;
299+
}
294300
$info .= $this->getComments($docBlock);
295301

296302
return $info;

0 commit comments

Comments
 (0)