@@ -138,15 +138,20 @@ public function postProcess(): void
138
138
parent ::postProcess ();
139
139
}
140
140
141
+ /**
142
+ * @throws SchemaException
143
+ */
141
144
private function validateEnum (PropertyInterface $ property ): bool
142
145
{
143
- $ throw = fn (string $ message ) => throw new SchemaException (
144
- sprintf (
145
- $ message ,
146
- $ property ->getName (),
147
- $ property ->getJsonSchema ()->getFile ()
148
- )
149
- );
146
+ $ throw = function (string $ message ) use ($ property ): void {
147
+ throw new SchemaException (
148
+ sprintf (
149
+ $ message ,
150
+ $ property ->getName (),
151
+ $ property ->getJsonSchema ()->getFile ()
152
+ )
153
+ );
154
+ };
150
155
151
156
$ json = $ property ->getJsonSchema ()->getJson ();
152
157
@@ -168,7 +173,7 @@ private function validateEnum(PropertyInterface $property): bool
168
173
|| count (array_uintersect (
169
174
$ json ['enum-map ' ],
170
175
$ json ['enum ' ],
171
- fn ($ a , $ b ) => $ a === $ b ? 0 : 1
176
+ function ($ a , $ b ): int { return $ a === $ b ? 0 : 1 ; }
172
177
)) !== count ($ json ['enum ' ])
173
178
)
174
179
) {
@@ -200,6 +205,12 @@ private function renderEnum(
200
205
$ cases [ucfirst ($ map ? array_search ($ value , $ map ) : $ value )] = var_export ($ value , true );
201
206
}
202
207
208
+ $ backedType = null ;
209
+ switch ($ this ->getArrayTypes ($ values )) {
210
+ case ['string ' ]: $ backedType = 'string ' ; break ;
211
+ case ['integer ' ]: $ backedType = 'int ' ; break ;
212
+ }
213
+
203
214
file_put_contents (
204
215
$ this ->targetDirectory . DIRECTORY_SEPARATOR . $ name . '.php ' ,
205
216
$ this ->renderer ->renderTemplate (
@@ -208,11 +219,7 @@ private function renderEnum(
208
219
'namespace ' => $ this ->namespace ,
209
220
'name ' => $ name ,
210
221
'cases ' => $ cases ,
211
- 'backedType ' => match ($ this ->getArrayTypes ($ values )) {
212
- ['string ' ] => 'string ' ,
213
- ['integer ' ] => 'int ' ,
214
- default => null ,
215
- },
222
+ 'backedType ' => $ backedType ,
216
223
]
217
224
)
218
225
);
0 commit comments