@@ -34,18 +34,36 @@ class MyCLabsEnumTypeMapper implements RootTypeMapperInterface
3434 /** @var array<string, EnumType> */
3535 private array $ cacheByName = [];
3636
37+ /** @var array<string, class-string<Enum>> */
38+ private array |null $ nameToClassMapping = null ;
39+
3740 /** @param NS[] $namespaces List of namespaces containing enums. Used when searching an enum by name. */
38- public function __construct (private readonly RootTypeMapperInterface $ next , private readonly AnnotationReader $ annotationReader , private readonly CacheInterface $ cacheService , private readonly array $ namespaces )
39- {
41+ public function __construct (
42+ private readonly RootTypeMapperInterface $ next ,
43+ private readonly AnnotationReader $ annotationReader ,
44+ private readonly CacheInterface $ cacheService ,
45+ private readonly array $ namespaces ,
46+ ) {
4047 }
4148
42- public function toGraphQLOutputType (Type $ type , OutputType |null $ subType , ReflectionMethod |ReflectionProperty $ reflector , DocBlock $ docBlockObj ): OutputType &\GraphQL \Type \Definition \Type
49+ public function toGraphQLOutputType (
50+ Type $ type ,
51+ OutputType |null $ subType ,
52+ ReflectionMethod |ReflectionProperty $ reflector ,
53+ DocBlock $ docBlockObj ,
54+ ): OutputType &\GraphQL \Type \Definition \Type
4355 {
4456 $ result = $ this ->map ($ type );
4557 return $ result ?? $ this ->next ->toGraphQLOutputType ($ type , $ subType , $ reflector , $ docBlockObj );
4658 }
4759
48- public function toGraphQLInputType (Type $ type , InputType |null $ subType , string $ argumentName , ReflectionMethod |ReflectionProperty $ reflector , DocBlock $ docBlockObj ): InputType &\GraphQL \Type \Definition \Type
60+ public function toGraphQLInputType (
61+ Type $ type ,
62+ InputType |null $ subType ,
63+ string $ argumentName ,
64+ ReflectionMethod |ReflectionProperty $ reflector ,
65+ DocBlock $ docBlockObj ,
66+ ): InputType &\GraphQL \Type \Definition \Type
4967 {
5068 $ result = $ this ->map ($ type );
5169 return $ result ?? $ this ->next ->toGraphQLInputType ($ type , $ subType , $ argumentName , $ reflector , $ docBlockObj );
@@ -83,6 +101,7 @@ private function mapByClassName(string $enumClass): EnumType|null
83101 return $ this ->cacheByName [$ type ->name ] = $ this ->cache [$ enumClass ] = $ type ;
84102 }
85103
104+
86105 private function getTypeName (ReflectionClass $ refClass ): string
87106 {
88107 $ enumType = $ this ->annotationReader ->getEnumTypeAnnotation ($ refClass );
@@ -131,9 +150,6 @@ public function mapNameToType(string $typeName): NamedType&\GraphQL\Type\Definit
131150 return $ this ->next ->mapNameToType ($ typeName );
132151 }
133152
134- /** @var array<string, class-string<Enum>> */
135- private array |null $ nameToClassMapping = null ;
136-
137153 /**
138154 * Go through all classes in the defined namespaces and loads the cache.
139155 *
@@ -150,6 +166,7 @@ private function getNameToClassMapping(): array
150166 continue ;
151167 }
152168
169+ /** @var class-string<Enum> $className */
153170 $ nameToClassMapping [$ this ->getTypeName ($ classRef )] = $ className ;
154171 }
155172 }
0 commit comments