Skip to content

Commit

Permalink
Do not apply heuristics of Collection<...>|Foo[] being resolved to Co…
Browse files Browse the repository at this point in the history
…llection of Foo

Closes phpstan/phpstan#6228
  • Loading branch information
ondrejmirtes committed Sep 30, 2024
1 parent fc66c24 commit fff8f09
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ parameters:
count: 1
path: src/PhpDoc/TypeNodeResolver.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Generic\\\\GenericObjectType is error\\-prone and deprecated\\.$#"
count: 1
path: src/PhpDoc/TypeNodeResolver.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\IterableType is error\\-prone and deprecated\\. Use Type\\:\\:isIterable\\(\\) instead\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion src/PhpDoc/TypeNodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ private function resolveUnionTypeNode(UnionTypeNode $typeNode, NameScope $nameSc
continue;
}

if ($type instanceof ObjectType) {
if ($type instanceof ObjectType && !$type instanceof GenericObjectType) {
$type = new IntersectionType([$type, new IterableType(new MixedType(), $arrayTypeType)]);
} elseif ($type instanceof ArrayType) {
$type = new ArrayType(new MixedType(), $arrayTypeType);
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/data/bug-4715.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Administration {}
class Company
{
/**
* @var Collection<int, Administration>|Administration[]
* @var Collection<int, Administration>
*/
protected Collection $administrations;

Expand All @@ -40,7 +40,7 @@ public function __construct()
}

/**
* @return Collection<int, Administration>|Administration[]
* @return Collection<int, Administration>
*/
public function getAdministrations() : Collection
{
Expand Down
16 changes: 16 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-6228.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Bug6228;

use function PHPStan\Testing\assertType;

class Bar
{
/**
* @param \DOMNodeList<\DOMNode>|\DOMNode|\DOMNode[]|string|null $node
*/
public function __construct($node)
{
assertType('array<DOMNode>|DOMNode|DOMNodeList<DOMNode>|string|null', $node);
}
}

0 comments on commit fff8f09

Please sign in to comment.