File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed
tests/Type/WebMozartAssert/data Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ This extension specifies types of values passed to:
3434* ` Assert::stringNotEmpty `
3535* ` Assert::float `
3636* ` Assert::numeric `
37+ * ` Assert::natural `
3738* ` Assert::integerish `
3839* ` Assert::boolean `
3940* ` Assert::scalar `
Original file line number Diff line number Diff line change @@ -225,6 +225,18 @@ private static function getExpressionResolvers(): array
225225 [$ value ]
226226 );
227227 },
228+ 'natural ' => function (Scope $ scope , Arg $ value ): \PhpParser \Node \Expr {
229+ return new \PhpParser \Node \Expr \BinaryOp \BooleanAnd (
230+ new \PhpParser \Node \Expr \FuncCall (
231+ new \PhpParser \Node \Name ('is_int ' ),
232+ [$ value ]
233+ ),
234+ new \PhpParser \Node \Expr \BinaryOp \GreaterOrEqual (
235+ $ value ->value ,
236+ new \PhpParser \Node \Scalar \LNumber (0 )
237+ )
238+ );
239+ },
228240 'boolean ' => function (Scope $ scope , Arg $ value ): \PhpParser \Node \Expr {
229241 return new \PhpParser \Node \Expr \FuncCall (
230242 new \PhpParser \Node \Name ('is_bool ' ),
Original file line number Diff line number Diff line change @@ -18,4 +18,14 @@ public function positiveInteger($a): void
1818 Assert::positiveInteger ($ b );
1919 \PHPStan \Testing \assertType ('*NEVER* ' , $ b );
2020 }
21+
22+ public function natural ($ a ): void
23+ {
24+ Assert::natural ($ a );
25+ \PHPStan \Testing \assertType ('int<0, max> ' , $ a );
26+
27+ $ b = -1 ;
28+ Assert::natural ($ b );
29+ \PHPStan \Testing \assertType ('*NEVER* ' , $ b );
30+ }
2131}
You can’t perform that action at this time.
0 commit comments