Skip to content

Commit 094662d

Browse files
Fix CS, PHPStan, and test failures
- Add missing `use function assert;` import in MutatingScope.php - Add @template generic type annotations to PossiblyImpureTipHelper::addTip() - Update ElseIfConstantConditionRuleTest::testBug6947 expected tip to include possibly-impure tip alongside treatPhpDocTypesAsCertain tip - Fix native-types-81.php: closures with `: string` return type now correctly resolve to native type `string` instead of `non-empty-string` (the previous `non-empty-string` was due to a closure type cache key collision between regular and native-promoted scopes) Co-authored-by: Ondřej Mirtes <ondrejmirtes@users.noreply.github.com>
1 parent 2abd912 commit 094662d

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

src/Analyser/MutatingScope.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
use Throwable;
146146
use ValueError;
147147
use function abs;
148+
use function assert;
148149
use function array_filter;
149150
use function array_key_exists;
150151
use function array_key_first;

src/Rules/Comparison/PossiblyImpureTipHelper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\Analyser\Scope;
88
use PHPStan\DependencyInjection\AutowiredParameter;
99
use PHPStan\DependencyInjection\AutowiredService;
10+
use PHPStan\Rules\RuleError;
1011
use PHPStan\Rules\RuleErrorBuilder;
1112
use function count;
1213

@@ -21,6 +22,11 @@ public function __construct(
2122
{
2223
}
2324

25+
/**
26+
* @template T of RuleError
27+
* @param RuleErrorBuilder<T> $ruleErrorBuilder
28+
* @return RuleErrorBuilder<T>
29+
*/
2430
public function addTip(
2531
Scope $scope,
2632
Expr $conditionExpr,

tests/PHPStan/Analyser/nsrt/native-types-81.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public function doFoo(): void
2525
};
2626

2727
assertType('non-empty-string', $f());
28-
assertNativeType('non-empty-string', $f());
28+
assertNativeType('string', $f());
2929

3030
assertType('non-empty-string', (function (): string {
3131
return funcWithANativeReturnType();
3232
})());
33-
assertNativeType('non-empty-string', (function (): string {
33+
assertNativeType('string', (function (): string {
3434
return funcWithANativeReturnType();
3535
})());
3636

tests/PHPStan/Rules/Comparison/ElseIfConstantConditionRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function testBug6947(): void
147147
[
148148
'Elseif condition is always false.',
149149
13,
150-
'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%</>.',
150+
"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%</>.\n• If Bug6947\HelloWorld::getValue() is impure, add <fg=cyan>@phpstan-impure</> PHPDoc tag above its declaration.",
151151
],
152152
]);
153153
}

0 commit comments

Comments
 (0)