Skip to content

Commit 00bad36

Browse files
committed
BetterNoopRule - shorter message
1 parent 9d8c16e commit 00bad36

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Rules/DeadCode/BetterNoopRule.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use PHPStan\Node\Printer\ExprPrinter;
99
use PHPStan\Rules\Rule;
1010
use PHPStan\Rules\RuleErrorBuilder;
11+
use function count;
12+
use function preg_split;
1113
use function sprintf;
1214

1315
/**
@@ -113,10 +115,16 @@ public function processNode(Node $node, Scope $scope): array
113115
return [];
114116
}
115117

118+
$exprString = $this->exprPrinter->printExpr($expr);
119+
$exprStringLines = preg_split('~\R~', $exprString, 2);
120+
if ($exprStringLines !== false && count($exprStringLines) > 1) {
121+
$exprString = $exprStringLines[0] . '';
122+
}
123+
116124
return [
117125
RuleErrorBuilder::message(sprintf(
118126
'Expression "%s" on a separate line does not do anything.',
119-
$this->exprPrinter->printExpr($expr),
127+
$exprString,
120128
))->line($expr->getStartLine())
121129
->identifier('expr.resultUnused')
122130
->build(),

0 commit comments

Comments
 (0)