Skip to content

Commit

Permalink
More accurately guessing Openapi mistype line and position (#1400)
Browse files Browse the repository at this point in the history
* Wrong DocParser Exception without context

Added $context param toDocParser->parse to keep context in exception.
According to:
- https://github.com/doctrine/annotations/blob/1.7/lib/Doctrine/Common/Annotations/DocParser.php#L440
- https://github.com/doctrine/annotations/blob/1.7/lib/Doctrine/Common/Annotations/DocParser.php#L342

* Phpstan failed hiden toString conversion

* Correct guessing line and position from error position of doctrine annotations

---------

Co-authored-by: Serghei Mateas <serghei.mateas@nuacom.ie>
  • Loading branch information
matiaspub and Serghei Mateas authored Jan 29, 2023
1 parent 4792289 commit 6f190e1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Analysers/DocBlockParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function fromComment(string $comment, Context $context): array
$errorMessage = $matches[1];
$errorPos = (int) $matches[2];
$atPos = strpos($comment, '@');
$context->line += substr_count($comment, "\n", 0, $atPos + $errorPos);
$context->line -= substr_count($comment, "\n", $atPos + $errorPos) + 1;
$lines = explode("\n", substr($comment, $atPos, $errorPos));
$context->character = strlen(array_pop($lines)) + 1; // position starts at 0 character starts at 1
$context->logger->error($errorMessage . ' in ' . $context, ['exception' => $e]);
Expand Down

0 comments on commit 6f190e1

Please sign in to comment.