forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomposer-array-bug.php
More file actions
64 lines (53 loc) · 1.99 KB
/
composer-array-bug.php
File metadata and controls
64 lines (53 loc) · 1.99 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
63
64
<?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'])) {
assertType("mixed~(0|0.0|''|'0'|array{}|false|null)", $this->config['authors']);
foreach ($this->config['authors'] as $key => $author) {
assertType("mixed", $this->config['authors']);
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("non-empty-array<mixed>&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("non-empty-array<mixed>&hasOffsetValue('authors', mixed~(0|0.0|''|'0'|array{}|false|null))", $this->config);
}
assertType("array<mixed>", $this->config);
}
}
}