From a26bfd9d12ee70f47ed522356d4fcad248a548a0 Mon Sep 17 00:00:00 2001 From: Andrew Lyons Date: Thu, 16 Jan 2025 21:53:28 +0800 Subject: [PATCH] [BetterPhpDocParser] Use str_contains() for DoctrineAnnotationDecorator (#6671) (#6674) The Lexer tokenizes at whitespace and certain other characters such as `.`, and `(`, If none of these tokens are present then the tokens are not split. For example in the string here: ``` @copyright Some Value. Something.({@link https://example.com}). ``` This is tokenised into: ``` '@copyright' ' ' 'Some' ' ' 'Value' '.' ' ' 'Something' .({@link' ' ' 'https' ':' '//example.com}).' ``` Both the open, and close, curly braces may be in the middle of a string and therefore the `str_contains` must be used for these cases. --- .../DoctrineAnnotationDecorator.php | 8 +++--- .../Fixture/with_description.php.inc | 6 +++-- .../InlineTags/Fixture/with_punctuation.inc | 27 +++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 tests/Issues/InlineTags/Fixture/with_punctuation.inc diff --git a/src/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php b/src/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php index 4c3c5e5927..5e7be1e51b 100644 --- a/src/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php +++ b/src/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php @@ -440,8 +440,8 @@ private function isClosedContent(string $composedContent): bool if ($composedTokenIterator->isCurrentTokenType( Lexer::TOKEN_OPEN_CURLY_BRACKET, Lexer::TOKEN_OPEN_PARENTHESES - ) || \str_starts_with($composedTokenIterator->currentTokenValue(), '{') - || \str_starts_with($composedTokenIterator->currentTokenValue(), '(') + ) || \str_contains($composedTokenIterator->currentTokenValue(), '{') + || \str_contains($composedTokenIterator->currentTokenValue(), '(') ) { ++$openBracketCount; } @@ -451,8 +451,8 @@ private function isClosedContent(string $composedContent): bool Lexer::TOKEN_CLOSE_CURLY_BRACKET, Lexer::TOKEN_CLOSE_PARENTHESES // sometimes it gets mixed int ") - ) || \str_ends_with($composedTokenIterator->currentTokenValue(), '}') - || \str_ends_with($composedTokenIterator->currentTokenValue(), ')')) { + ) || \str_contains($composedTokenIterator->currentTokenValue(), '}') + || \str_contains($composedTokenIterator->currentTokenValue(), ')')) { ++$closeBracketCount; } diff --git a/tests/Issues/InlineTags/Fixture/with_description.php.inc b/tests/Issues/InlineTags/Fixture/with_description.php.inc index bf6de99f75..3c01d41c71 100644 --- a/tests/Issues/InlineTags/Fixture/with_description.php.inc +++ b/tests/Issues/InlineTags/Fixture/with_description.php.inc @@ -3,7 +3,8 @@ use PHPUnit\Framework\TestCase; /** - * @copyright Example {@link https://example.com} some description + * @copyright Example {@link https://example.com}. Additional description. + * @todo Do this.{@link https://example.com}. * @covers \Tests\BarController */ class WithDescription extends TestCase @@ -17,7 +18,8 @@ class WithDescription extends TestCase use PHPUnit\Framework\TestCase; /** - * @copyright Example {@link https://example.com} some description + * @copyright Example {@link https://example.com}. Additional description. + * @todo Do this.{@link https://example.com}. */ #[\PHPUnit\Framework\Attributes\CoversClass(\Tests\BarController::class)] class WithDescription extends TestCase diff --git a/tests/Issues/InlineTags/Fixture/with_punctuation.inc b/tests/Issues/InlineTags/Fixture/with_punctuation.inc new file mode 100644 index 0000000000..0f6e4f7063 --- /dev/null +++ b/tests/Issues/InlineTags/Fixture/with_punctuation.inc @@ -0,0 +1,27 @@ + +----- +