|
10 | 10 | use GraphQL\Type\Definition\Type as GraphQLType;
|
11 | 11 | use MyCLabs\Enum\Enum;
|
12 | 12 | use phpDocumentor\Reflection\DocBlock;
|
| 13 | +use phpDocumentor\Reflection\DocBlockFactory; |
13 | 14 | use phpDocumentor\Reflection\Type;
|
14 | 15 | use phpDocumentor\Reflection\Types\Object_;
|
15 | 16 | use ReflectionClass;
|
@@ -119,7 +120,35 @@ private function mapByClassName(string $enumClass): EnumType|null
|
119 | 120 | $reflectionEnum->isBacked() &&
|
120 | 121 | (string) $reflectionEnum->getBackingType() === 'string';
|
121 | 122 |
|
122 |
| - $type = new EnumType($enumClass, $typeName, $useValues); |
| 123 | + $docBlockFactory = DocBlockFactory::createInstance(); |
| 124 | + |
| 125 | + $enumDescription = null; |
| 126 | + $docComment = $reflectionEnum->getDocComment(); |
| 127 | + if ($docComment) { |
| 128 | + $docBlock = $docBlockFactory->create($docComment); |
| 129 | + $enumDescription = $docBlock->getSummary(); |
| 130 | + } |
| 131 | + |
| 132 | + $enumCaseDescriptions = []; |
| 133 | + $enumCaseDeprecationReasons = []; |
| 134 | + foreach ($reflectionEnum->getCases() as $reflectionEnumCase) { |
| 135 | + $docComment = $reflectionEnumCase->getDocComment(); |
| 136 | + if ($docComment) { |
| 137 | + $docBlock = $docBlockFactory->create($docComment); |
| 138 | + $enumCaseDescription = $docBlock->getSummary(); |
| 139 | + |
| 140 | + $enumCaseDescriptions[$reflectionEnumCase->getName()] = $enumCaseDescription; |
| 141 | + $deprecation = $docBlock->getTagsByName('deprecated')[0] ?? null; |
| 142 | + |
| 143 | + if ($deprecation) { |
| 144 | + $enumCaseDeprecationReasons[$reflectionEnumCase->getName()] = (string) $deprecation; |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + /** @var array<string, string> $enumCaseDescriptions */ |
| 150 | + /** @var array<string, string> $enumCaseDeprecationReasons */ |
| 151 | + $type = new EnumType($enumClass, $typeName, $enumDescription, $enumCaseDescriptions, $enumCaseDeprecationReasons, $useValues); |
123 | 152 |
|
124 | 153 | return $this->cacheByName[$type->name] = $this->cache[$enumClass] = $type;
|
125 | 154 | }
|
|
0 commit comments