Skip to content

Commit 783390a

Browse files
committed
use constructor arg
1 parent 2cf2d60 commit 783390a

8 files changed

+14
-14
lines changed

src/Rules/TooWideTypehints/TooWideFunctionReturnTypehintRule.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
7-
use PHPStan\DependencyInjection\AutowiredParameter;
87
use PHPStan\DependencyInjection\RegisteredRule;
98
use PHPStan\Node\FunctionReturnStatementsNode;
109
use PHPStan\Rules\Rule;
@@ -19,8 +18,6 @@ final class TooWideFunctionReturnTypehintRule implements Rule
1918

2019
public function __construct(
2120
private TooWideTypeCheck $check,
22-
#[AutowiredParameter(ref: '%featureToggles.reportTooWideBool%')]
23-
private bool $reportTooWideBool,
2421
)
2522
{
2623
}
@@ -43,7 +40,6 @@ public function processNode(Node $node, Scope $scope): array
4340
$function->getName(),
4441
),
4542
false,
46-
$this->reportTooWideBool,
4743
);
4844
}
4945

src/Rules/TooWideTypehints/TooWideMethodReturnTypehintRule.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public function __construct(
2121
#[AutowiredParameter(ref: '%checkTooWideReturnTypesInProtectedAndPublicMethods%')]
2222
private bool $checkProtectedAndPublicMethods,
2323
private TooWideTypeCheck $check,
24-
#[AutowiredParameter(ref: '%featureToggles.reportTooWideBool%')]
25-
private bool $reportTooWideBool,
2624
)
2725
{
2826
}
@@ -61,7 +59,6 @@ public function processNode(Node $node, Scope $scope): array
6159
$method->getName(),
6260
),
6361
!$isFirstDeclaration && !$method->isPrivate(),
64-
$this->reportTooWideBool,
6562
);
6663
}
6764

src/Rules/TooWideTypehints/TooWideTypeCheck.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\Rules\TooWideTypehints;
44

5+
use PHPStan\DependencyInjection\AutowiredParameter;
56
use PHPStan\DependencyInjection\AutowiredService;
67
use PHPStan\Node\ClassPropertyNode;
78
use PHPStan\Node\FunctionReturnStatementsNode;
@@ -21,6 +22,13 @@
2122
final class TooWideTypeCheck
2223
{
2324

25+
public function __construct(
26+
#[AutowiredParameter(ref: '%featureToggles.reportTooWideBool%')]
27+
private bool $reportTooWideBool,
28+
)
29+
{
30+
}
31+
2432
/**
2533
* @return list<IdentifierRuleError>
2634
*/
@@ -66,13 +74,12 @@ public function checkFunction(
6674
Type $functionReturnType,
6775
string $functionDescription,
6876
bool $checkDescendantClass,
69-
bool $reportTooWideBool,
7077
): array
7178
{
7279
$functionReturnType = TypeUtils::resolveLateResolvableTypes($functionReturnType);
7380

7481
if (!$functionReturnType instanceof UnionType) {
75-
if (!$functionReturnType->isBoolean()->yes() || !$reportTooWideBool) {
82+
if (!$functionReturnType->isBoolean()->yes() || !$this->reportTooWideBool) {
7683
return [];
7784
}
7885
}

tests/PHPStan/Rules/TooWideTypehints/TooWideArrowFunctionReturnTypehintRuleTest.php

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

tests/PHPStan/Rules/TooWideTypehints/TooWideClosureReturnTypehintRuleTest.php

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

tests/PHPStan/Rules/TooWideTypehints/TooWideFunctionReturnTypehintRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TooWideFunctionReturnTypehintRuleTest extends RuleTestCase
1515

1616
protected function getRule(): Rule
1717
{
18-
return new TooWideFunctionReturnTypehintRule(new TooWideTypeCheck(), $this->reportTooWideBool);
18+
return new TooWideFunctionReturnTypehintRule(new TooWideTypeCheck($this->reportTooWideBool));
1919
}
2020

2121
public function testRule(): void

tests/PHPStan/Rules/TooWideTypehints/TooWideMethodReturnTypehintRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TooWideMethodReturnTypehintRuleTest extends RuleTestCase
1919

2020
protected function getRule(): Rule
2121
{
22-
return new TooWideMethodReturnTypehintRule($this->checkProtectedAndPublicMethods, new TooWideTypeCheck(), $this->reportTooWideBool);
22+
return new TooWideMethodReturnTypehintRule($this->checkProtectedAndPublicMethods, new TooWideTypeCheck($this->reportTooWideBool));
2323
}
2424

2525
public function testPrivate(): void

tests/PHPStan/Rules/TooWideTypehints/TooWidePropertyTypeRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected function getRule(): Rule
2121
return new TooWidePropertyTypeRule(
2222
new DirectReadWritePropertiesExtensionProvider([]),
2323
new PropertyReflectionFinder(),
24-
new TooWideTypeCheck(),
24+
new TooWideTypeCheck($this->reportTooWideBool),
2525
$this->reportTooWideBool,
2626
);
2727
}

0 commit comments

Comments
 (0)