Skip to content

Commit 2f71247

Browse files
committed
PromoteParameterRule - more precise line for LineRuleError
1 parent ca86412 commit 2f71247

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Rules/Playground/PromoteParameterRule.php

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

55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
7+
use PHPStan\Rules\LineRuleError;
78
use PHPStan\Rules\Rule;
89
use PHPStan\Rules\RuleErrorBuilder;
910
use function sprintf;
@@ -45,10 +46,13 @@ public function processNode(Node $node, Scope $scope): array
4546

4647
$errors = [];
4748
foreach ($this->rule->processNode($node, $scope) as $error) {
48-
$errors[] = RuleErrorBuilder::message($error->getMessage())
49+
$builder = RuleErrorBuilder::message($error->getMessage())
4950
->identifier('phpstanPlayground.configParameter')
50-
->tip(sprintf('This error would be reported if the <fg=cyan>%s: true</> parameter was enabled in your <fg=cyan>%%configurationFile%%</>.', $this->parameterName))
51-
->build();
51+
->tip(sprintf('This error would be reported if the <fg=cyan>%s: true</> parameter was enabled in your <fg=cyan>%%configurationFile%%</>.', $this->parameterName));
52+
if ($error instanceof LineRuleError) {
53+
$builder->line($error->getLine());
54+
}
55+
$errors[] = $builder->build();
5256
}
5357

5458
return $errors;

tests/PHPStan/Rules/Playground/PromoteParameterRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testRule(): void
3232
$this->analyse([__DIR__ . '/data/promote-parameter.php'], [
3333
[
3434
'Class PromoteParameter\Foo has an uninitialized property $test. Give it default value or assign it in the constructor.',
35-
5,
35+
8,
3636
'This error would be reported if the <fg=cyan>checkUninitializedProperties: true</> parameter was enabled in your <fg=cyan>%configurationFile%</>.',
3737
],
3838
]);

0 commit comments

Comments
 (0)