Skip to content

Commit 90870bc

Browse files
committed
Native intersection types are detected as references
1 parent 0e97b88 commit 90870bc

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

SlevomatCodingStandard/Helpers/ReferencedNameHelper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
use const T_PARAM_NAME;
4848
use const T_STRING;
4949
use const T_TRAIT;
50+
use const T_TYPE_INTERSECTION;
5051
use const T_TYPE_UNION;
5152
use const T_USE;
5253
use const T_VARIABLE;
@@ -211,6 +212,13 @@ private static function getReferenceType(File $phpcsFile, int $nameStartPointer,
211212
return ReferencedName::TYPE_CLASS;
212213
}
213214

215+
if (
216+
$tokens[$previousTokenBeforeStartPointer]['code'] === T_TYPE_INTERSECTION
217+
|| $tokens[$nextTokenAfterEndPointer]['code'] === T_TYPE_INTERSECTION
218+
) {
219+
return ReferencedName::TYPE_CLASS;
220+
}
221+
214222
if ($tokens[$nextTokenAfterEndPointer]['code'] === T_BITWISE_AND) {
215223
$tokenAfterNextToken = TokenHelper::findNextEffective($phpcsFile, $nextTokenAfterEndPointer + 1);
216224

tests/Helpers/ReferencedNameHelperTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public function testGetAllReferencedNames(): void
6464
['\Union\UnionType4', false, false],
6565
['UnionType5', false, false],
6666
['UnionType6', false, false],
67+
['IntersectionType', false, false],
68+
['\Intersection\IntersectionType2', false, false],
69+
['\Intersection\IntersectionType3', false, false],
70+
['IntersectionType4', false, false],
71+
['\Intersection\IntersectionType5', false, false],
72+
['IntersectionType6', false, false],
73+
['\Intersection\IntersectionType7', false, false],
6774
['str_pad', true, false],
6875
['STR_PAD_RIGHT', false, true],
6976
['EnumType', false, false],

tests/Helpers/data/lotsOfReferencedNames.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php // lint >= 8.0
1+
<?php // lint >= 8.1
22

33
namespace FooNamespace;
44

@@ -166,6 +166,21 @@ public function call2(bool|UnionType6 $union)
166166

167167
}
168168

169+
class WithIntersection
170+
{
171+
172+
private IntersectionType&\Intersection\IntersectionType2 $intersection;
173+
174+
public function call(\Intersection\IntersectionType3|IntersectionType4|\Intersection\IntersectionType5 $intersection)
175+
{
176+
}
177+
178+
public function call2(): IntersectionType6&\Intersection\IntersectionType7
179+
{
180+
}
181+
182+
}
183+
169184
echo str_pad('123', 1, pad_type: STR_PAD_RIGHT, enum_type: EnumType::VALUE());
170185

171186

0 commit comments

Comments
 (0)