File tree 4 files changed +34
-0
lines changed
tests/Type/WebMozartAssert
4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ This extension specifies types of values passed to:
55
55
* ` Assert::implementsInterface `
56
56
* ` Assert::classExists `
57
57
* ` Assert::interfaceExists `
58
+ * ` Assert::validArrayKey `
58
59
* ` Assert::minCount `
59
60
* ` Assert::inArray `
60
61
* ` Assert::oneOf `
Original file line number Diff line number Diff line change @@ -320,6 +320,18 @@ private static function getExpressionResolvers(): array
320
320
[$ key , $ array ]
321
321
);
322
322
},
323
+ 'validArrayKey ' => function (Scope $ scope , Arg $ value ): \PhpParser \Node \Expr {
324
+ return new \PhpParser \Node \Expr \BinaryOp \BooleanOr (
325
+ new \PhpParser \Node \Expr \FuncCall (
326
+ new \PhpParser \Node \Name ('is_int ' ),
327
+ [$ value ]
328
+ ),
329
+ new \PhpParser \Node \Expr \FuncCall (
330
+ new \PhpParser \Node \Name ('is_string ' ),
331
+ [$ value ]
332
+ )
333
+ );
334
+ },
323
335
'true ' => function (Scope $ scope , Arg $ expr ): \PhpParser \Node \Expr {
324
336
return new \PhpParser \Node \Expr \BinaryOp \Identical (
325
337
$ expr ->value ,
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ class AssertTypeSpecifyingExtensionTest extends TypeInferenceTestCase
12
12
*/
13
13
public function dataFileAsserts (): iterable
14
14
{
15
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/array.php ' );
15
16
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/data.php ' );
16
17
}
17
18
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ use Webmozart \Assert \Assert ;
6
+
7
+ class Foo
8
+ {
9
+ /**
10
+ * @param mixed $a
11
+ */
12
+ public function validArrayKey ($ a , bool $ b ): void
13
+ {
14
+ Assert::validArrayKey ($ a );
15
+ \PHPStan \Testing \assertType ('int|string ' , $ a );
16
+
17
+ Assert::validArrayKey ($ b );
18
+ \PHPStan \Testing \assertType ('*NEVER* ' , $ b );
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments