File tree Expand file tree Collapse file tree 4 files changed +34
-0
lines changed
tests/Type/WebMozartAssert Expand file tree Collapse file tree 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:
5555* ` Assert::implementsInterface `
5656* ` Assert::classExists `
5757* ` Assert::interfaceExists `
58+ * ` Assert::validArrayKey `
5859* ` Assert::minCount `
5960* ` Assert::inArray `
6061* ` Assert::oneOf `
Original file line number Diff line number Diff line change @@ -320,6 +320,18 @@ private static function getExpressionResolvers(): array
320320 [$ key , $ array ]
321321 );
322322 },
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+ },
323335 'true ' => function (Scope $ scope , Arg $ expr ): \PhpParser \Node \Expr {
324336 return new \PhpParser \Node \Expr \BinaryOp \Identical (
325337 $ expr ->value ,
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ class AssertTypeSpecifyingExtensionTest extends TypeInferenceTestCase
1212 */
1313 public function dataFileAsserts (): iterable
1414 {
15+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/array.php ' );
1516 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/data.php ' );
1617 }
1718
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