Skip to content

Commit

Permalink
Better enum support
Browse files Browse the repository at this point in the history
  • Loading branch information
phpfui committed Apr 29, 2024
1 parent 29c0261 commit 1f50a42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/PHPFUI/InstaDoc/Section/CodeCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 8 additions & 2 deletions src/PHPFUI/InstaDoc/Section/Doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 1f50a42

Please sign in to comment.