Skip to content

Commit 0af1c83

Browse files
mavimoondrejmirtes
authored andcommitted
check that stringNotEmpty is a string
1 parent 9ff202d commit 0af1c83

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This extension specifies types of values passed to:
1111

1212
* `Assert::integer`
1313
* `Assert::string`
14+
* `Assert::stringNotEmpty`
1415
* `Assert::float`
1516
* `Assert::numeric`
1617
* `Assert::boolean`

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

+6
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ private static function getExpressionResolvers(): array
180180
[$value]
181181
);
182182
},
183+
'stringNotEmpty' => function (Scope $scope, Arg $value): ?\PhpParser\Node\Expr {
184+
return new \PhpParser\Node\Expr\FuncCall(
185+
new \PhpParser\Node\Name('is_string'),
186+
[$value]
187+
);
188+
},
183189
'float' => function (Scope $scope, Arg $value): ?\PhpParser\Node\Expr {
184190
return new \PhpParser\Node\Expr\FuncCall(
185191
new \PhpParser\Node\Name('is_float'),

tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ public function testExtension(): void
145145
'Variable $ab is: array<PHPStan\Type\WebMozartAssert\Foo>',
146146
113,
147147
],
148+
[
149+
'Variable $ac is: string',
150+
116,
151+
],
148152
]);
149153
}
150154

tests/Type/WebMozartAssert/data/data.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Foo
88
{
99

10-
public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $r, $s, ?int $t, ?int $u, $x, $aa, array $ab)
10+
public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $r, $s, ?int $t, ?int $u, $x, $aa, array $ab, $ac)
1111
{
1212
$a;
1313

@@ -111,6 +111,9 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
111111

112112
Assert::allSubclassOf($ab, self::class);
113113
$ab;
114+
115+
Assert::stringNotEmpty($ac);
116+
$ac;
114117
}
115118

116119
}

0 commit comments

Comments
 (0)