Skip to content

Commit f129a3c

Browse files
committed
simplify
1 parent 0fc4fd3 commit f129a3c

File tree

6 files changed

+18
-20
lines changed

6 files changed

+18
-20
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
use PHPStan\Type\Generic\TemplateTypeVarianceMap;
182182
use PHPStan\Type\IntegerType;
183183
use PHPStan\Type\IntersectionType;
184+
use PHPStan\Type\IterableType;
184185
use PHPStan\Type\MixedType;
185186
use PHPStan\Type\NeverType;
186187
use PHPStan\Type\NullType;
@@ -6322,10 +6323,7 @@ private function processVarAnnotation(MutatingScope $scope, array $variableNames
63226323

63236324
private function getForeachIterateeType(): Type
63246325
{
6325-
return TypeCombinator::union(
6326-
new ArrayType(new MixedType(), new MixedType()),
6327-
new ObjectType(Traversable::class),
6328-
);
6326+
return new IterableType(new MixedType(), new MixedType());
63296327
}
63306328

63316329
private function enterForeach(MutatingScope $scope, MutatingScope $originalScope, Foreach_ $stmt): MutatingScope

tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5816,7 +5816,7 @@ public static function dataIterable(): array
58165816
'$iterableWithoutTypehint[0]',
58175817
],
58185818
[
5819-
'array|Traversable',
5819+
'iterable',
58205820
'$iterableWithIterableTypehint',
58215821
],
58225822
[
@@ -5828,7 +5828,7 @@ public static function dataIterable(): array
58285828
'$mixed',
58295829
],
58305830
[
5831-
'array<Iterables\Bar>|(iterable<Iterables\Bar>&Traversable)',
5831+
'iterable<Iterables\Bar>',
58325832
'$iterableWithConcreteTypehint',
58335833
],
58345834
[
@@ -5844,7 +5844,7 @@ public static function dataIterable(): array
58445844
'$this->doBar()',
58455845
],
58465846
[
5847-
'array<Iterables\Baz>|(iterable<Iterables\Baz>&Traversable)',
5847+
'iterable<Iterables\Baz>',
58485848
'$this->doBaz()',
58495849
],
58505850
[

tests/PHPStan/Analyser/nsrt/bug-13270a.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class HelloWorld
1414
public function test(array $data): void
1515
{
1616
foreach($data as $k => $v) {
17-
assertType('non-empty-array', $data);
17+
assertType('non-empty-array<mixed>', $data);
1818
$data[$k]['a'] = true;
1919
assertType("non-empty-array<(non-empty-array&hasOffsetValue('a', true))|(ArrayAccess&hasOffsetValue('a', true))>", $data);
2020
foreach($data[$k] as $val) {

tests/PHPStan/Analyser/nsrt/bug-13312.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function foo(array $arr): void {
3535
function fooBar(mixed $mixed): void {
3636
assertType('mixed', $mixed);
3737
foreach ($mixed as $v) {
38-
assertType('array|Traversable', $mixed); // could be non-empty-array|Traversable
38+
assertType('iterable', $mixed); // could be non-empty-array|Traversable
3939
}
4040
assertType('mixed', $mixed);
4141

tests/PHPStan/Analyser/nsrt/composer-array-bug.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@ public function doFoo(): void
1818
if (!empty($this->config['authors'])) {
1919
assertType("mixed~(0|0.0|''|'0'|array{}|false|null)", $this->config['authors']);
2020
foreach ($this->config['authors'] as $key => $author) {
21-
assertType("array|Traversable", $this->config['authors']);
21+
assertType("iterable", $this->config['authors']);
2222

2323
if (!is_array($author)) {
2424
$this->errors[] = 'authors.'.$key.' : should be an array, '.gettype($author).' given';
25-
assertType("array|Traversable", $this->config['authors']);
25+
assertType("iterable", $this->config['authors']);
2626
unset($this->config['authors'][$key]);
27-
assertType("array|Traversable", $this->config['authors']);
27+
assertType("iterable", $this->config['authors']);
2828
continue;
2929
}
30-
assertType("array|Traversable", $this->config['authors']);
30+
assertType("iterable", $this->config['authors']);
3131
foreach (['homepage', 'email', 'name', 'role'] as $authorData) {
3232
if (isset($author[$authorData]) && !is_string($author[$authorData])) {
3333
$this->errors[] = 'authors.'.$key.'.'.$authorData.' : invalid value, must be a string';
3434
unset($this->config['authors'][$key][$authorData]);
3535
}
3636
}
3737
if (isset($author['homepage'])) {
38-
assertType("array|Traversable", $this->config['authors']);
38+
assertType("iterable", $this->config['authors']);
3939
unset($this->config['authors'][$key]['homepage']);
40-
assertType("array|Traversable", $this->config['authors']);
40+
assertType("iterable", $this->config['authors']);
4141
}
4242
if (isset($author['email']) && !filter_var($author['email'], FILTER_VALIDATE_EMAIL)) {
4343
unset($this->config['authors'][$key]['email']);

tests/PHPStan/Analyser/nsrt/composer-non-empty-array-after-unset.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public function doFoo()
1515
if (!empty($this->config['authors'])) {
1616
assertType("mixed~(0|0.0|''|'0'|array{}|false|null)", $this->config['authors']);
1717
foreach ($this->config['authors'] as $key => $author) {
18-
assertType("array|Traversable", $this->config['authors']);
18+
assertType("iterable", $this->config['authors']);
1919
if (!is_array($author)) {
2020
unset($this->config['authors'][$key]);
21-
assertType("array|Traversable", $this->config['authors']);
21+
assertType("iterable", $this->config['authors']);
2222
continue;
2323
}
2424
foreach (['homepage', 'email', 'name', 'role'] as $authorData) {
@@ -33,11 +33,11 @@ public function doFoo()
3333
unset($this->config['authors'][$key]['email']);
3434
}
3535
if (empty($this->config['authors'][$key])) {
36-
assertType("array|Traversable", $this->config['authors']);
36+
assertType("iterable", $this->config['authors']);
3737
unset($this->config['authors'][$key]);
38-
assertType("array|Traversable", $this->config['authors']);
38+
assertType("iterable", $this->config['authors']);
3939
}
40-
assertType("array|Traversable", $this->config['authors']);
40+
assertType("iterable", $this->config['authors']);
4141
}
4242
assertType("mixed~(0|0.0|''|'0'|array{}|false|null)", $this->config['authors']);
4343
}

0 commit comments

Comments
 (0)