forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-14549.php
More file actions
62 lines (53 loc) · 1.62 KB
/
Copy pathbug-14549.php
File metadata and controls
62 lines (53 loc) · 1.62 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php declare(strict_types = 1);
namespace Bug14549;
use function PHPStan\Testing\assertType;
class Foo
{
public function foo(array $task): void
{
if (\is_callable($task)) {
assertType('list{class-string|object, string}&callable(): mixed', $task);
assertType('class-string|object', $task[0]);
assertType('string', $task[1]);
foreach ($task as $key => $value) {
assertType('object|string', $value);
assertType('0|1', $key);
}
}
}
public function testCallableArrayIterableTypes(callable $value): void
{
if (is_array($value)) {
assertType('list{class-string|object, string}&callable(): mixed', $value);
foreach ($value as $key => $val) {
assertType('0|1', $key);
assertType('object|string', $val);
}
}
}
/** @param array{string, string} $task */
public function testConstantArrayNarrowing(array $task): void
{
if (\is_callable($task)) {
assertType('list{class-string, string}&callable(): mixed', $task);
assertType('class-string', $task[0]);
assertType('string', $task[1]);
}
}
/** @param array<string> $task */
public function testTypedArrayNarrowing(array $task): void
{
if (\is_callable($task)) {
// When value type is string, intersect with class-string|object gives class-string
// and intersect with string gives string
assertType('list{class-string, string}&callable(): mixed', $task);
}
}
/** @param callable-array $value */
public function testCallableArrayPhpDoc(array $value): void
{
assertType('list{class-string|object, string}&callable(): mixed', $value);
assertType('class-string|object', $value[0]);
assertType('string', $value[1]);
}
}