forked from phpstan/phpstan-src
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreg_replace_callback_shapes.php
47 lines (42 loc) · 1.03 KB
/
preg_replace_callback_shapes.php
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
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace PregReplaceCallbackMatchShapes;
use function PHPStan\Testing\assertType;
function (string $s): void {
preg_replace_callback(
'/(foo)?(bar)?(baz)?/',
function ($matches) {
assertType("array{string, 'foo'|null, 'bar'|null, 'baz'|null}", $matches);
return '';
},
$s,
-1,
$count,
PREG_UNMATCHED_AS_NULL
);
};
function (string $s): void {
preg_replace_callback(
'/(foo)?(bar)?(baz)?/',
function ($matches) {
assertType("list{0: array{string, int<-1, max>}, 1?: array{''|'foo', int<-1, max>}, 2?: array{''|'bar', int<-1, max>}, 3?: array{'baz', int<-1, max>}}", $matches);
return '';
},
$s,
-1,
$count,
PREG_OFFSET_CAPTURE
);
};
function (string $s): void {
preg_replace_callback(
'/(foo)?(bar)?(baz)?/',
function ($matches) {
assertType("array{array{string|null, int<-1, max>}, array{'foo'|null, int<-1, max>}, array{'bar'|null, int<-1, max>}, array{'baz'|null, int<-1, max>}}", $matches);
return '';
},
$s,
-1,
$count,
PREG_OFFSET_CAPTURE|PREG_UNMATCHED_AS_NULL
);
};