Skip to content

Commit e08596b

Browse files
schlndhkukulich
authored andcommitted
SlevomatCodingStandard.TypeHints.PropertyTypeHint: fix inconsistent enableIntersectionTypeHint
PropertyTypeHintSniff handled enableIntersectionTypeHint differently than ReturnTypeHintSniff and ParameterTypeHintSniff. This appears to be an unintentional (i.e. using enableUnionTypeHint instead). It lead to it suggesting to replace an interesection annotation with a native typehint with enableNativeTypeHint=true, enableUnionTypeHint=true and enableIntersectionTypeHint=false.
1 parent c5cf9b5 commit e08596b

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/PropertyTypeHintSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private function checkTypeHint(
305305
}
306306
$typeHintsWithConvertedUnion = array_unique($typeHintsWithConvertedUnion);
307307

308-
if (count($typeHintsWithConvertedUnion) > 1 && !$canTryUnionTypeHint && !$this->enableUnionTypeHint) {
308+
if (count($typeHintsWithConvertedUnion) > 1 && !$canTryUnionTypeHint && !$this->enableIntersectionTypeHint) {
309309
$this->reportUselessSuppress($phpcsFile, $propertyPointer, $isSuppressedNativeTypeHint, $suppressNameNativeTypeHint);
310310
return;
311311
}

tests/Sniffs/TypeHints/data/parameterTypeHintWithUnionNoErrors.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,18 @@ public function arrayAndArrayHash($a)
2121
{
2222
}
2323

24+
/**
25+
* @param A&B $a
26+
*/
27+
public function intersectionWithoutNativeTypeHint($a)
28+
{
29+
}
30+
31+
/**
32+
* @param A&B $a
33+
*/
34+
public function intersectionWithBroadNativeTypeHint(A $a)
35+
{
36+
}
37+
2438
}

tests/Sniffs/TypeHints/data/propertyTypeHintEnabledNativeWithUnionNoErrors.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ class Whatever
1313
*/
1414
protected $arrayAndArrayHash;
1515

16+
/** @var A&B */
17+
public $intersectionWithoutNativeTypeHint;
18+
19+
/** @var A&B */
20+
public A $intersectionWitBroadNativeTypeHint;
21+
1622
}

tests/Sniffs/TypeHints/data/returnTypeHintWithUnionNoErrors.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,18 @@ public function arrayAndArrayHash()
1919
{
2020
}
2121

22+
/**
23+
* @return A&B
24+
*/
25+
public function intersectionWithoutNativeTypeHint()
26+
{
27+
}
28+
29+
/**
30+
* @return A&B
31+
*/
32+
public function intersectionWithBroadNativeTypeHint(): A
33+
{
34+
}
35+
2236
}

0 commit comments

Comments
 (0)