@@ -198,7 +198,9 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
198
198
throw new RuntimeException (sprintf ('Unsupported env var prefix "%s". ' , $ prefix ));
199
199
}
200
200
201
- return null ;
201
+ if (!\in_array ($ prefix , ['string ' , 'bool ' , 'not ' , 'int ' , 'float ' ], true )) {
202
+ return null ;
203
+ }
202
204
}
203
205
204
206
if ('shuffle ' === $ prefix ) {
@@ -207,7 +209,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
207
209
return $ env ;
208
210
}
209
211
210
- if (!\is_scalar ($ env )) {
212
+ if (null !== $ env && !\is_scalar ($ env )) {
211
213
throw new RuntimeException (sprintf ('Non-scalar env var "%s" cannot be cast to "%s". ' , $ name , $ prefix ));
212
214
}
213
215
@@ -222,15 +224,15 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
222
224
}
223
225
224
226
if ('int ' === $ prefix ) {
225
- if (false === $ env = filter_var ($ env , \FILTER_VALIDATE_INT ) ?: filter_var ($ env , \FILTER_VALIDATE_FLOAT )) {
227
+ if (null !== $ env && false === $ env = filter_var ($ env , \FILTER_VALIDATE_INT ) ?: filter_var ($ env , \FILTER_VALIDATE_FLOAT )) {
226
228
throw new RuntimeException (sprintf ('Non-numeric env var "%s" cannot be cast to int. ' , $ name ));
227
229
}
228
230
229
231
return (int ) $ env ;
230
232
}
231
233
232
234
if ('float ' === $ prefix ) {
233
- if (false === $ env = filter_var ($ env , \FILTER_VALIDATE_FLOAT )) {
235
+ if (null !== $ env && false === $ env = filter_var ($ env , \FILTER_VALIDATE_FLOAT )) {
234
236
throw new RuntimeException (sprintf ('Non-numeric env var "%s" cannot be cast to float. ' , $ name ));
235
237
}
236
238
0 commit comments