<?php private function getConstantNames(ReflectionClass $reflection): array
{
return array_merge(...array_values((array_map(
function (ReflectionClassConstant $constant) use ($reflection): array {
foreach ($reflection->getTraits() as $trait) {
if ($trait->hasConstant($constant->getName())) {
return [];
}
}
if ($constant->class !== $reflection->name) {
return [];
}
$value = $constant->getValue();
if ($value instanceof BackedEnum) {
return is_string($value->value)
? [$value->name, $value->value]
: [$value->name];
}
return is_string($value)
? [$constant->name, $value]
: [$constant->name];
},
$reflection->getReflectionConstants()
))));
}