Skip to content

Commit fff8f09

Browse files
committed
Do not apply heuristics of Collection<...>|Foo[] being resolved to Collection of Foo
Closes phpstan/phpstan#6228
1 parent fc66c24 commit fff8f09

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

phpstan-baseline.neon

+5
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ parameters:
180180
count: 1
181181
path: src/PhpDoc/TypeNodeResolver.php
182182

183+
-
184+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Generic\\\\GenericObjectType is error\\-prone and deprecated\\.$#"
185+
count: 1
186+
path: src/PhpDoc/TypeNodeResolver.php
187+
183188
-
184189
message: "#^Doing instanceof PHPStan\\\\Type\\\\IterableType is error\\-prone and deprecated\\. Use Type\\:\\:isIterable\\(\\) instead\\.$#"
185190
count: 1

src/PhpDoc/TypeNodeResolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ private function resolveUnionTypeNode(UnionTypeNode $typeNode, NameScope $nameSc
568568
continue;
569569
}
570570

571-
if ($type instanceof ObjectType) {
571+
if ($type instanceof ObjectType && !$type instanceof GenericObjectType) {
572572
$type = new IntersectionType([$type, new IterableType(new MixedType(), $arrayTypeType)]);
573573
} elseif ($type instanceof ArrayType) {
574574
$type = new ArrayType(new MixedType(), $arrayTypeType);

tests/PHPStan/Analyser/data/bug-4715.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Administration {}
3030
class Company
3131
{
3232
/**
33-
* @var Collection<int, Administration>|Administration[]
33+
* @var Collection<int, Administration>
3434
*/
3535
protected Collection $administrations;
3636

@@ -40,7 +40,7 @@ public function __construct()
4040
}
4141

4242
/**
43-
* @return Collection<int, Administration>|Administration[]
43+
* @return Collection<int, Administration>
4444
*/
4545
public function getAdministrations() : Collection
4646
{
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Bug6228;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Bar
8+
{
9+
/**
10+
* @param \DOMNodeList<\DOMNode>|\DOMNode|\DOMNode[]|string|null $node
11+
*/
12+
public function __construct($node)
13+
{
14+
assertType('array<DOMNode>|DOMNode|DOMNodeList<DOMNode>|string|null', $node);
15+
}
16+
}

0 commit comments

Comments
 (0)