Skip to content

Commit 42bf0a3

Browse files
Rework
1 parent c720728 commit 42bf0a3

3 files changed

Lines changed: 12 additions & 16 deletions

File tree

‎src/Analyser/RuleErrorTransformer.php‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function transform(
7676
) {
7777
$line = $ruleError->getLine();
7878
} else {
79-
$line = self::getLineFromNode($node);
79+
$line = self::getStartLineFromNode($node);
8080
}
8181
if (
8282
$ruleError instanceof FileRuleError
@@ -168,20 +168,16 @@ public function transform(
168168
);
169169
}
170170

171-
public static function getLineFromNode(Node $node): int
171+
public static function getStartLineFromNode(Node $node): int
172172
{
173-
if ($node instanceof PropertyAssignNode) {
174-
return self::getLineFromNode($node->getPropertyFetch());
175-
}
176-
177-
if (
178-
$node instanceof Node\Expr\PropertyFetch
179-
|| $node instanceof Node\Expr\MethodCall
180-
) {
181-
return $node->name->getStartLine();
182-
}
183-
184-
return $node->getStartLine();
173+
$line = match (true) {
174+
$node instanceof PropertyAssignNode => self::getStartLineFromNode($node->getPropertyFetch()),
175+
$node instanceof Node\Expr\PropertyFetch,
176+
$node instanceof Node\Expr\MethodCall => $node->name->getStartLine(),
177+
default => -1,
178+
};
179+
180+
return $line !== -1 ? $line : $node->getStartLine();
185181
}
186182

187183
}

‎src/Rules/FunctionCallParametersCheck.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function check(
9090
string $namedArgumentMessage,
9191
): array
9292
{
93-
$funcCallLine = RuleErrorTransformer::getLineFromNode($funcCall);
93+
$funcCallLine = RuleErrorTransformer::getStartLineFromNode($funcCall);
9494

9595
$functionParametersMinCount = 0;
9696
$functionParametersMaxCount = 0;

‎tests/PHPStan/Rules/Properties/data/bug-14150.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class HelloWorld
99
/**
1010
* @return $this
1111
*/
12-
public function x(): static
12+
public function x()
1313
{
1414
return $this;
1515
}

0 commit comments

Comments
 (0)