File tree Expand file tree Collapse file tree
rules-tests/TypedCollections/Rector/NullsafeMethodCall/RemoveNullsafeOnCollectionRector/Fixture
rules/TypedCollections/TypeAnalyzer Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ ?>
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 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}
You can’t perform that action at this time.
0 commit comments