forked from phpstan/phpstan-src
/
composer-array-bug.php
61 lines (51 loc) · 1.81 KB
/
composer-array-bug.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace ComposerArrayBug;
use function PHPStan\Testing\assertType;
class Foo
{
/** @var mixed[] */
private $config;
/** @var string[] */
private $errors;
public function doFoo(): void
{
if (!empty($this->config['authors'])) {
foreach ($this->config['authors'] as $key => $author) {
if (!is_array($author)) {
$this->errors[] = 'authors.'.$key.' : should be an array, '.gettype($author).' given';
assertType("mixed", $this->config['authors']);
unset($this->config['authors'][$key]);
assertType("mixed", $this->config['authors']);
continue;
}
assertType("mixed", $this->config['authors']);
foreach (['homepage', 'email', 'name', 'role'] as $authorData) {
if (isset($author[$authorData]) && !is_string($author[$authorData])) {
$this->errors[] = 'authors.'.$key.'.'.$authorData.' : invalid value, must be a string';
unset($this->config['authors'][$key][$authorData]);
}
}
if (isset($author['homepage'])) {
assertType("mixed", $this->config['authors']);
unset($this->config['authors'][$key]['homepage']);
assertType("mixed", $this->config['authors']);
}
if (isset($author['email']) && !filter_var($author['email'], FILTER_VALIDATE_EMAIL)) {
unset($this->config['authors'][$key]['email']);
}
if (empty($this->config['authors'][$key])) {
unset($this->config['authors'][$key]);
}
}
assertType("array&hasOffsetValue('authors', mixed)", $this->config);
assertType("mixed", $this->config['authors']);
if (empty($this->config['authors'])) {
unset($this->config['authors']);
assertType("array<mixed~'authors', mixed>", $this->config);
} else {
assertType("array&hasOffsetValue('authors', mixed~0|0.0|''|'0'|array{}|false|null)", $this->config);
}
assertType('array', $this->config);
}
}
}