@@ -9,10 +9,23 @@ class Foo
99 /**
1010 * @param non-empty-string $str
1111 * @param string $maybe_empty_string
12+ * @param null|string $nullable_string
13+ * @param null|non-empty-string $nullable_non_empty_string
14+ * @param int $int
1215 * @param positive-int $positive_int
1316 * @param negative-int $negative_int
17+ * @param bool $bool
1418 */
15- public function run (string $ str , string $ maybe_empty_string , int $ int , int $ positive_int , int $ negative_int ): void
19+ public function run (
20+ string $ str ,
21+ string $ maybe_empty_string ,
22+ null |string $ nullable_string ,
23+ null |string $ nullable_non_empty_string ,
24+ int $ int ,
25+ int $ positive_int ,
26+ int $ negative_int ,
27+ bool $ bool ,
28+ ): void
1629 {
1730 assertType ('non-empty-string ' , $ str );
1831
@@ -139,5 +152,50 @@ public function run(string $str, string $maybe_empty_string, int $int, int $posi
139152
140153 $ return = filter_var ('0x10 ' , FILTER_VALIDATE_INT , FILTER_FLAG_ALLOW_HEX );
141154 assertType ('16 ' , $ return );
155+
156+ $ return = filter_var (true , options: FILTER_FLAG_EMPTY_STRING_NULL );
157+ assertType ("'1' " , $ return );
158+
159+ $ return = filter_var (false , options: FILTER_FLAG_EMPTY_STRING_NULL );
160+ assertType ('null ' , $ return );
161+
162+ $ return = filter_var ($ bool , options: FILTER_FLAG_EMPTY_STRING_NULL );
163+ assertType ("'1'|null " , $ return );
164+
165+ $ return = filter_var (0.0 , options: FILTER_FLAG_EMPTY_STRING_NULL );
166+ assertType ("'-0'|'0' " , $ return );
167+
168+ $ return = filter_var (0 , options: FILTER_FLAG_EMPTY_STRING_NULL );
169+ assertType ("'0' " , $ return );
170+
171+ $ return = filter_var (null , options: FILTER_FLAG_EMPTY_STRING_NULL );
172+ assertType ('null ' , $ return );
173+
174+ $ return = filter_var ($ nullable_string , options: FILTER_FLAG_EMPTY_STRING_NULL );
175+ assertType ('non-empty-string|null ' , $ return );
176+
177+ $ return = filter_var ($ nullable_non_empty_string , options: FILTER_FLAG_EMPTY_STRING_NULL );
178+ assertType ('non-empty-string|null ' , $ return );
179+
180+ $ return = filter_var ($ this ->anyOf (0.0 , true ), options: FILTER_FLAG_EMPTY_STRING_NULL );
181+ assertType ("'-0'|'0'|'1' " , $ return );
182+
183+ $ return = filter_var ($ this ->anyOf ($ bool , $ maybe_empty_string ), options: FILTER_FLAG_EMPTY_STRING_NULL );
184+ assertType ("non-empty-string|null " , $ return );
185+
186+ $ return = filter_var ($ this ->anyOf (0 , null ), options: FILTER_FLAG_EMPTY_STRING_NULL );
187+ assertType ("'0'|null " , $ return );
188+ }
189+
190+ /**
191+ * @template T
192+ * @template U
193+ * @param T $a
194+ * @param U $b
195+ * @return T|U
196+ */
197+ private function anyOf (mixed $ a , mixed $ b ): mixed
198+ {
199+ return random_int (0 , 1 ) ? $ a : $ b ;
142200 }
143201}
0 commit comments