Skip to content

Commit e227ffd

Browse files
committed
Merge remote-tracking branch 'origin/1.6.x' into 2.0.x
2 parents 90006f2 + daeec74 commit e227ffd

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

rules.neon

+2
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ services:
171171
class: PHPStan\Rules\Cast\UselessCastRule
172172
arguments:
173173
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
174+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
174175

175176
-
176177
class: PHPStan\Rules\Classes\RequireParentConstructCallRule
@@ -198,6 +199,7 @@ services:
198199
arguments:
199200
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
200201
checkNullables: %checkNullables%
202+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
201203

202204
-
203205
class: PHPStan\Rules\Functions\ClosureUsesThisRule

src/Rules/Cast/UselessCastRule.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ class UselessCastRule implements Rule
2020

2121
private bool $treatPhpDocTypesAsCertain;
2222

23-
public function __construct(bool $treatPhpDocTypesAsCertain)
23+
private bool $treatPhpDocTypesAsCertainTip;
24+
25+
public function __construct(
26+
bool $treatPhpDocTypesAsCertain,
27+
bool $treatPhpDocTypesAsCertainTip
28+
)
2429
{
2530
$this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain;
31+
$this->treatPhpDocTypesAsCertainTip = $treatPhpDocTypesAsCertainTip;
2632
}
2733

2834
public function getNodeType(): string
@@ -54,7 +60,11 @@ public function processNode(Node $node, Scope $scope): array
5460
return $ruleErrorBuilder;
5561
}
5662

57-
return $ruleErrorBuilder->tip('Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.');
63+
if (!$this->treatPhpDocTypesAsCertainTip) {
64+
return $ruleErrorBuilder;
65+
}
66+
67+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5868
};
5969
return [
6070
$addTip(RuleErrorBuilder::message(sprintf(

src/Rules/Functions/ArrayFilterStrictRule.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@ class ArrayFilterStrictRule implements Rule
2929

3030
private bool $checkNullables;
3131

32+
private bool $treatPhpDocTypesAsCertainTip;
33+
3234
public function __construct(
3335
ReflectionProvider $reflectionProvider,
3436
bool $treatPhpDocTypesAsCertain,
35-
bool $checkNullables
37+
bool $checkNullables,
38+
bool $treatPhpDocTypesAsCertainTip
3639
)
3740
{
3841
$this->reflectionProvider = $reflectionProvider;
3942
$this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain;
4043
$this->checkNullables = $checkNullables;
44+
$this->treatPhpDocTypesAsCertainTip = $treatPhpDocTypesAsCertainTip;
4145
}
4246

4347
public function getNodeType(): string
@@ -132,8 +136,8 @@ public function processNode(Node $node, Scope $scope): array
132136
$callbackType->describe(VerbosityLevel::typeOnly()),
133137
))->identifier('arrayFilter.strict');
134138

135-
if (!$this->isCallbackTypeNull($nativeCallbackType) && $this->treatPhpDocTypesAsCertain) {
136-
$errorBuilder->tip('Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.');
139+
if ($this->treatPhpDocTypesAsCertainTip && !$this->isCallbackTypeNull($nativeCallbackType) && $this->treatPhpDocTypesAsCertain) {
140+
$errorBuilder->treatPhpDocTypesAsCertainTip();
137141
}
138142

139143
return [$errorBuilder->build()];

tests/Rules/Cast/UselessCastRuleTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ class UselessCastRuleTest extends RuleTestCase
1515

1616
protected function getRule(): Rule
1717
{
18-
return new UselessCastRule($this->treatPhpDocTypesAsCertain);
18+
return new UselessCastRule(
19+
$this->treatPhpDocTypesAsCertain,
20+
true,
21+
);
1922
}
2023

2124
protected function shouldTreatPhpDocTypesAsCertain(): bool

tests/Rules/Functions/ArrayFilterStrictRuleTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ class ArrayFilterStrictRuleTest extends RuleTestCase
1717

1818
protected function getRule(): Rule
1919
{
20-
return new ArrayFilterStrictRule($this->createReflectionProvider(), $this->treatPhpDocTypesAsCertain, $this->checkNullables);
20+
return new ArrayFilterStrictRule(
21+
$this->createReflectionProvider(),
22+
$this->treatPhpDocTypesAsCertain,
23+
$this->checkNullables,
24+
true,
25+
);
2126
}
2227

2328
protected function shouldTreatPhpDocTypesAsCertain(): bool

0 commit comments

Comments
 (0)