Skip to content

Commit 6f2b8d0

Browse files
committed
skip it
1 parent 4c39104 commit 6f2b8d0

3 files changed

Lines changed: 73 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: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@
88
return;
99
}
1010

11-
interface Collection
11+
/**
12+
* The missing (SPL) Collection/Array/OrderedMap interface.
13+
*
14+
* A Collection resembles the nature of a regular PHP array. That is,
15+
* it is essentially an <b>ordered map</b> that can also be used
16+
* like a list.
17+
*
18+
* A Collection has an internal iterator just like a PHP array. In addition,
19+
* a Collection can be iterated with external iterators, which is preferable.
20+
* To use an external iterator simply use the foreach language construct to
21+
* iterate over the collection (which calls {@link getIterator()} internally) or
22+
* explicitly retrieve an iterator though {@link getIterator()} which can then be
23+
* used to iterate over the collection.
24+
* You can not rely on the internal iterator of the collection being at a certain
25+
* position unless you explicitly positioned it before. Prefer iteration with
26+
* external iterators.
27+
*
28+
* @psalm-template TKey of array-key
29+
* @psalm-template T
30+
* @template-extends ReadableCollection<TKey, T>
31+
* @template-extends ArrayAccess<TKey, T>
32+
*/
33+
interface Collection extends ReadableCollection, \ArrayAccess
1234
{
1335
}

0 commit comments

Comments
 (0)