Skip to content

Commit 1611a88

Browse files
committed
Separate feature toggle for reportNestedTooWideType, turned off temporarily
1 parent ae08dcc commit 1611a88

11 files changed

+33
-10
lines changed

conf/bleedingEdge.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ parameters:
1212
checkExtensionsForComparisonOperators: true
1313
reportTooWideBool: true
1414
rawMessageInBaseline: true
15+
reportNestedTooWideType: false

conf/config.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ parameters:
3636
checkExtensionsForComparisonOperators: false
3737
reportTooWideBool: false
3838
rawMessageInBaseline: false
39+
reportNestedTooWideType: false
3940
fileExtensions:
4041
- php
4142
checkAdvancedIsset: false

conf/parametersSchema.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ parametersSchema:
3939
checkExtensionsForComparisonOperators: bool()
4040
reportTooWideBool: bool()
4141
rawMessageInBaseline: bool()
42+
reportNestedTooWideType: bool()
4243
])
4344
fileExtensions: listOf(string())
4445
checkAdvancedIsset: bool()

src/Rules/TooWideTypehints/TooWideTypeCheck.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public function __construct(
3636
private PropertyReflectionFinder $propertyReflectionFinder,
3737
#[AutowiredParameter(ref: '%featureToggles.reportTooWideBool%')]
3838
private bool $reportTooWideBool,
39+
#[AutowiredParameter(ref: '%featureToggles.reportNestedTooWideType%')]
40+
private bool $reportNestedTooWideType,
3941
)
4042
{
4143
}
@@ -105,7 +107,7 @@ public function checkProperty(
105107
);
106108
}
107109

108-
if (!$this->reportTooWideBool) {
110+
if (!$this->reportNestedTooWideType) {
109111
return [];
110112
}
111113

@@ -227,7 +229,7 @@ public function checkFunctionReturnType(
227229
);
228230
}
229231

230-
if (!$this->reportTooWideBool) {
232+
if (!$this->reportNestedTooWideType) {
231233
return [];
232234
}
233235

@@ -290,7 +292,7 @@ public function checkParameterOutType(
290292
$parameterOutType = TypeUtils::resolveLateResolvableTypes($parameterOutType);
291293
$narrowedType = $this->narrowType($parameterOutType, $actualVariableType, $scope, false, false);
292294
if ($narrowedType->equals($parameterOutType)) {
293-
if (!$this->reportTooWideBool) {
295+
if (!$this->reportNestedTooWideType) {
294296
return [];
295297
}
296298

tests/PHPStan/Rules/TooWideTypehints/TooWideArrowFunctionReturnTypehintRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TooWideArrowFunctionReturnTypehintRuleTest extends RuleTestCase
1515
protected function getRule(): Rule
1616
{
1717
return new TooWideArrowFunctionReturnTypehintRule(
18-
new TooWideTypeCheck(new PropertyReflectionFinder(), true),
18+
new TooWideTypeCheck(new PropertyReflectionFinder(), true, true),
1919
);
2020
}
2121

tests/PHPStan/Rules/TooWideTypehints/TooWideClosureReturnTypehintRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TooWideClosureReturnTypehintRuleTest extends RuleTestCase
1515
protected function getRule(): Rule
1616
{
1717
return new TooWideClosureReturnTypehintRule(
18-
new TooWideTypeCheck(new PropertyReflectionFinder(), true),
18+
new TooWideTypeCheck(new PropertyReflectionFinder(), true, true),
1919
);
2020
}
2121

tests/PHPStan/Rules/TooWideTypehints/TooWideFunctionParameterOutTypeRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TooWideFunctionParameterOutTypeRuleTest extends RuleTestCase
1515
protected function getRule(): TRule
1616
{
1717
return new TooWideFunctionParameterOutTypeRule(new TooWideParameterOutTypeCheck(
18-
new TooWideTypeCheck(new PropertyReflectionFinder(), true),
18+
new TooWideTypeCheck(new PropertyReflectionFinder(), true, true),
1919
));
2020
}
2121

tests/PHPStan/Rules/TooWideTypehints/TooWideFunctionReturnTypehintRuleTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ class TooWideFunctionReturnTypehintRuleTest extends RuleTestCase
1515

1616
private bool $reportTooWideBool = false;
1717

18+
private bool $reportNestedTooWideType = false;
19+
1820
protected function getRule(): Rule
1921
{
20-
return new TooWideFunctionReturnTypehintRule(new TooWideTypeCheck(new PropertyReflectionFinder(), $this->reportTooWideBool));
22+
return new TooWideFunctionReturnTypehintRule(new TooWideTypeCheck(new PropertyReflectionFinder(), $this->reportTooWideBool, $this->reportNestedTooWideType));
2123
}
2224

2325
public function testRule(): void
@@ -74,6 +76,7 @@ public function testBug10312a(): void
7476
public function testBug13384cPhp82(): void
7577
{
7678
$this->reportTooWideBool = true;
79+
$this->reportNestedTooWideType = true;
7780
$this->analyse([__DIR__ . '/data/bug-13384c.php'], [
7881
[
7982
'Function Bug13384c\doFoo() never returns true so the return type can be changed to false.',
@@ -98,6 +101,7 @@ public function testBug13384cPhp82(): void
98101
public function testBug13384cPrePhp82(): void
99102
{
100103
$this->reportTooWideBool = true;
104+
$this->reportNestedTooWideType = true;
101105
$this->analyse([__DIR__ . '/data/bug-13384c.php'], [
102106
[
103107
'Function Bug13384c\doFooPhpdoc() never returns false so the return type can be changed to true.',
@@ -118,6 +122,7 @@ public function testBug13384cOff(): void
118122
public function testNestedTooWideType(): void
119123
{
120124
$this->reportTooWideBool = true;
125+
$this->reportNestedTooWideType = true;
121126
$this->analyse([__DIR__ . '/data/nested-too-wide-function-return-type.php'], [
122127
[
123128
'Return type array<array{int, bool}> of function NestedTooWideFunctionReturnType\dataProvider() can be narrowed to array<array{int, false}>.',

tests/PHPStan/Rules/TooWideTypehints/TooWideMethodParameterOutTypeRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function getRule(): TRule
1818
{
1919
return new TooWideMethodParameterOutTypeRule(
2020
new TooWideParameterOutTypeCheck(
21-
new TooWideTypeCheck(new PropertyReflectionFinder(), true),
21+
new TooWideTypeCheck(new PropertyReflectionFinder(), true, true),
2222
),
2323
$this->checkProtectedAndPublicMethods,
2424
);

tests/PHPStan/Rules/TooWideTypehints/TooWideMethodReturnTypehintRuleTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ class TooWideMethodReturnTypehintRuleTest extends RuleTestCase
1818

1919
private bool $reportTooWideBool = false;
2020

21+
private bool $reportNestedTooWideType = false;
22+
2123
protected function getRule(): Rule
2224
{
23-
return new TooWideMethodReturnTypehintRule($this->checkProtectedAndPublicMethods, new TooWideTypeCheck(new PropertyReflectionFinder(), $this->reportTooWideBool));
25+
return new TooWideMethodReturnTypehintRule($this->checkProtectedAndPublicMethods, new TooWideTypeCheck(new PropertyReflectionFinder(), $this->reportTooWideBool, $this->reportNestedTooWideType));
2426
}
2527

2628
public function testPrivate(): void
@@ -227,6 +229,7 @@ public function testBug10312d(): void
227229
public function testBug13384c(): void
228230
{
229231
$this->reportTooWideBool = true;
232+
$this->reportNestedTooWideType = true;
230233
$this->analyse([__DIR__ . '/data/bug-13384c.php'], [
231234
[
232235
'Method Bug13384c\Bug13384c::doBar() never returns true so the return type can be changed to false.',
@@ -259,6 +262,7 @@ public function testBug13384c(): void
259262
public function testBug13384cPrePhp82(): void
260263
{
261264
$this->reportTooWideBool = true;
265+
$this->reportNestedTooWideType = true;
262266
$this->analyse([__DIR__ . '/data/bug-13384c.php'], [
263267
[
264268
'Method Bug13384c\Bug13384c::doBarPhpdoc() never returns false so the return type can be changed to true.',
@@ -279,6 +283,7 @@ public function testBug13384cOff(): void
279283
public function testNestedTooWideType(): void
280284
{
281285
$this->reportTooWideBool = true;
286+
$this->reportNestedTooWideType = true;
282287
$this->analyse([__DIR__ . '/data/nested-too-wide-method-return-type.php'], [
283288
[
284289
'Return type array<array{int, bool}> of method NestedTooWideMethodReturnType\Foo::dataProvider() can be narrowed to array<array{int, false}>.',

0 commit comments

Comments
 (0)