Skip to content

Commit f12542a

Browse files
committed
Temporary "accepts" tips about too-wide nested types
1 parent 13d6378 commit f12542a

File tree

6 files changed

+9
-0
lines changed

6 files changed

+9
-0
lines changed

src/Rules/TooWideTypehints/TooWideTypeCheck.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public function checkProperty(
128128
$narrowedPhpDocType->describe(VerbosityLevel::getRecommendedLevelByType($narrowedPhpDocType)),
129129
))->identifier('property.nestedUnusedType')
130130
->line($node->getStartLine())
131+
->acceptsReasonsTip($narrowedPhpDocType->accepts($phpDocPropertyType, true)->reasons)
131132
->build(),
132133
];
133134
}
@@ -249,6 +250,7 @@ public function checkFunctionReturnType(
249250
$narrowedPhpDocType->describe(VerbosityLevel::getRecommendedLevelByType($narrowedPhpDocType)),
250251
))->identifier('return.nestedUnusedType')
251252
->line($node->getStartLine())
253+
->acceptsReasonsTip($narrowedPhpDocType->accepts($phpDocFunctionReturnType, true)->reasons)
252254
->build(),
253255
];
254256
}
@@ -310,6 +312,7 @@ public function checkParameterOutType(
310312
$narrowedType->describe(VerbosityLevel::getRecommendedLevelByType($narrowedType)),
311313
))->identifier(sprintf('%s.nestedUnusedType', $identifierPart))
312314
->line($startLine)
315+
->acceptsReasonsTip($narrowedType->accepts($parameterOutType, true)->reasons)
313316
->build(),
314317
];
315318
}

tests/PHPStan/Rules/TooWideTypehints/TooWideFunctionParameterOutTypeRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function testNestedTooWideType(): void
4545
[
4646
'PHPDoc tag @param-out type array<array{int, bool}> of function NestedTooWideFunctionParameterOutType\doFoo() can be narrowed to array<array{int, false}>.',
4747
9,
48+
'Offset 1 (false) does not accept type bool.',
4849
],
4950
]);
5051
}

tests/PHPStan/Rules/TooWideTypehints/TooWideFunctionReturnTypehintRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function testNestedTooWideType(): void
122122
[
123123
'Return type array<array{int, bool}> of function NestedTooWideFunctionReturnType\dataProvider() can be narrowed to array<array{int, false}>.',
124124
8,
125+
'Offset 1 (false) does not accept type bool.',
125126
],
126127
]);
127128
}

tests/PHPStan/Rules/TooWideTypehints/TooWideMethodParameterOutTypeRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function testNestedTooWideType(): void
139139
[
140140
'PHPDoc tag @param-out type array<array{int, bool}> of method NestedTooWideMethodParameterOutType\Foo::doFoo() can be narrowed to array<array{int, false}>.',
141141
12,
142+
'Offset 1 (false) does not accept type bool.',
142143
],
143144
]);
144145
}

tests/PHPStan/Rules/TooWideTypehints/TooWideMethodReturnTypehintRuleTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,12 @@ public function testNestedTooWideType(): void
283283
[
284284
'Return type array<array{int, bool}> of method NestedTooWideMethodReturnType\Foo::dataProvider() can be narrowed to array<array{int, false}>.',
285285
11,
286+
'Offset 1 (false) does not accept type bool.',
286287
],
287288
[
288289
'Return type array<array{int|null}> of method NestedTooWideMethodReturnType\Foo::dataProvider2() can be narrowed to array<array{int}>.',
289290
28,
291+
'Offset 0 (int) does not accept type int|null.',
290292
],
291293
]);
292294
}

tests/PHPStan/Rules/TooWideTypehints/TooWidePropertyTypeRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function testNestedTooWideType(): void
118118
[
119119
'Type array<array{int, bool}> of property NestedTooWidePropertyType\Foo::$a can be narrowed to array<array{int, false}>.',
120120
9,
121+
'Offset 1 (false) does not accept type bool.',
121122
],
122123
]);
123124
}

0 commit comments

Comments
 (0)