mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-12-02 09:27:58 +01:00
Add Error::getMessageWithColumnInfo()
This commit is contained in:
parent
c5e0c3d7e2
commit
f3c7dc9d89
@ -90,11 +90,7 @@ foreach ($files as $file) {
|
|||||||
|
|
||||||
function formatErrorMessage(PhpParser\Error $e, $code, $withColumnInfo) {
|
function formatErrorMessage(PhpParser\Error $e, $code, $withColumnInfo) {
|
||||||
if ($withColumnInfo && $e->hasColumnInfo()) {
|
if ($withColumnInfo && $e->hasColumnInfo()) {
|
||||||
$startLine = $e->getStartLine();
|
return $e->getMessageWithColumnInfo($code);
|
||||||
$endLine = $e->getEndLine();
|
|
||||||
$startColumn = $e->getStartColumn($code);
|
|
||||||
$endColumn = $e->getEndColumn($code);
|
|
||||||
return $e->getRawMessage() . " from $startLine:$startColumn to $endLine:$endColumn";
|
|
||||||
} else {
|
} else {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,14 @@ class Error extends \RuntimeException
|
|||||||
return $this->toColumn($code, $this->attributes['endFilePos']);
|
return $this->toColumn($code, $this->attributes['endFilePos']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMessageWithColumnInfo($code) {
|
||||||
|
return sprintf(
|
||||||
|
'%s from %d:%d to %d:%d', $this->getRawMessage(),
|
||||||
|
$this->getStartLine(), $this->getStartColumn($code),
|
||||||
|
$this->getEndLine(), $this->getEndColumn($code)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private function toColumn($code, $pos) {
|
private function toColumn($code, $pos) {
|
||||||
if ($pos > strlen($code)) {
|
if ($pos > strlen($code)) {
|
||||||
throw new \RuntimeException('Invalid position information');
|
throw new \RuntimeException('Invalid position information');
|
||||||
|
@ -60,8 +60,7 @@ class CodeParsingTest extends CodeTestAbstract
|
|||||||
|
|
||||||
private function formatErrorMessage(Error $e, $code) {
|
private function formatErrorMessage(Error $e, $code) {
|
||||||
if ($e->hasColumnInfo()) {
|
if ($e->hasColumnInfo()) {
|
||||||
return $e->getRawMessage() . ' from ' . $e->getStartLine() . ':' . $e->getStartColumn($code)
|
return $e->getMessageWithColumnInfo($code);
|
||||||
. ' to ' . $e->getEndLine() . ':' . $e->getEndColumn($code);
|
|
||||||
} else {
|
} else {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user