forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-11580.php
More file actions
35 lines (29 loc) · 937 Bytes
/
bug-11580.php
File metadata and controls
35 lines (29 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace Bug11580;
use function PHPStan\Testing\assertType;
final class HelloWorld
{
public function bad(string $in): void
{
$matches = [];
if (preg_match('~^/xxx/([\w\-]+)/?([\w\-]+)?/?$~', $in, $matches)) {
assertType('array{0: non-falsy-string, 1: non-empty-string, 2?: non-empty-string}', $matches);
}
}
public function bad2(string $in): void
{
$matches = [];
$result = preg_match('~^/xxx/([\w\-]+)/?([\w\-]+)?/?$~', $in, $matches);
if ($result) {
assertType('array{0: non-falsy-string, 1: non-empty-string, 2?: non-empty-string}', $matches);
}
}
public function bad3(string $in): void
{
$result = preg_match('~^/xxx/([\w\-]+)/?([\w\-]+)?/?$~', $in, $matches);
assertType('array{}|array{0: non-falsy-string, 1: non-empty-string, 2?: non-empty-string}', $matches);
if ($result) {
assertType('array{0: non-falsy-string, 1: non-empty-string, 2?: non-empty-string}', $matches);
}
}
}