File tree Expand file tree Collapse file tree 1 file changed +26
-7
lines changed Expand file tree Collapse file tree 1 file changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -12,18 +12,12 @@ class EnumCollector extends DefaultCollector
12
12
{
13
13
public function getTransformedType (ReflectionClass $ class ): ?TransformedType
14
14
{
15
- $ transformers = array_map ('get_class ' , $ this ->config ->getTransformers ());
16
-
17
- if (! \in_array (EnumTransformer::class, $ transformers , true )) {
15
+ if (!$ this ->shouldCollect ($ class )) {
18
16
return null ;
19
17
}
20
18
21
19
$ reflector = ClassTypeReflector::create ($ class );
22
20
23
- if (! $ reflector ->getReflectionClass ()->implementsInterface (BackedEnum::class)) {
24
- return null ;
25
- }
26
-
27
21
$ transformedType = $ reflector ->getType ()
28
22
? $ this ->resolveAlreadyTransformedType ($ reflector )
29
23
: $ this ->resolveTypeViaTransformer ($ reflector );
@@ -35,4 +29,29 @@ public function getTransformedType(ReflectionClass $class): ?TransformedType
35
29
36
30
return $ transformedType ;
37
31
}
32
+
33
+ protected function shouldCollect (ReflectionClass $ class ): bool
34
+ {
35
+ $ transformers = array_map ('get_class ' , $ this ->config ->getTransformers ());
36
+
37
+ $ hasEnumTransformer = \count (
38
+ array_filter ($ transformers , function (string $ transformer ) {
39
+ if ($ transformer === EnumTransformer::class) {
40
+ return true ;
41
+ }
42
+
43
+ return is_subclass_of ($ transformer , EnumTransformer::class);
44
+ }),
45
+ ) > 0 ;
46
+
47
+ if (!$ hasEnumTransformer ) {
48
+ return false ;
49
+ }
50
+
51
+ if (!$ class ->implementsInterface (BackedEnum::class)) {
52
+ return false ;
53
+ }
54
+
55
+ return true ;
56
+ }
38
57
}
You can’t perform that action at this time.
0 commit comments