Skip to content

Commit 398d913

Browse files
authored
skip it (#435)
1 parent 4c39104 commit 398d913

3 files changed

Lines changed: 57 additions & 2 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\TypedCollections\Rector\NullsafeMethodCall\RemoveNullsafeOnCollectionRector\Fixture;
4+
5+
use Doctrine\Common\Collections\Collection;
6+
7+
final class IncludeMixOfDocblock
8+
{
9+
/**
10+
* @var Collection<string>|null
11+
*/
12+
public Collection $items;
13+
14+
public function someMethod()
15+
{
16+
$values = $this->items?->count();
17+
}
18+
}
19+
20+
?>
21+
-----
22+
<?php
23+
24+
namespace Rector\Doctrine\Tests\TypedCollections\Rector\NullsafeMethodCall\RemoveNullsafeOnCollectionRector\Fixture;
25+
26+
use Doctrine\Common\Collections\Collection;
27+
28+
final class IncludeMixOfDocblock
29+
{
30+
/**
31+
* @var Collection<string>|null
32+
*/
33+
public Collection $items;
34+
35+
public function someMethod()
36+
{
37+
$values = $this->items->count();
38+
}
39+
}
40+
41+
?>

rules/TypedCollections/TypeAnalyzer/CollectionTypeDetector.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public function __construct(
2323
public function isCollectionNonNullableType(Expr $expr): bool
2424
{
2525
$exprType = $this->nodeTypeResolver->getType($expr);
26+
2627
return $this->isCollectionObjectType($exprType);
2728
}
2829

2930
public function isCollectionType(Expr $expr): bool
3031
{
3132
$exprType = $this->nodeTypeResolver->getType($expr);
32-
3333
if ($exprType instanceof IntersectionType) {
3434
foreach ($exprType->getTypes() as $intersectionedType) {
3535
if ($this->isCollectionObjectType($intersectionedType)) {
@@ -48,6 +48,14 @@ public function isCollectionType(Expr $expr): bool
4848

4949
private function isCollectionObjectType(Type $exprType): bool
5050
{
51+
if ($exprType instanceof IntersectionType) {
52+
foreach ($exprType->getTypes() as $intersectionedType) {
53+
if ($this->isCollectionObjectType($intersectionedType)) {
54+
return true;
55+
}
56+
}
57+
}
58+
5159
if (! $exprType instanceof ObjectType) {
5260
return false;
5361
}

stubs/Common/Collections/Collection.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
return;
99
}
1010

11-
interface Collection
11+
/**
12+
* @psalm-template TKey of array-key
13+
* @psalm-template T
14+
* @template-extends ReadableCollection<TKey, T>
15+
* @template-extends ArrayAccess<TKey, T>
16+
*/
17+
interface Collection extends ReadableCollection, \ArrayAccess
1218
{
1319
}

0 commit comments

Comments
 (0)