Skip to content

Commit

Permalink
[BetterPhpDocParser] Use str_contains() for DoctrineAnnotationDecorat…
Browse files Browse the repository at this point in the history
…or (#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.
  • Loading branch information
andrewnicols authored Jan 16, 2025
1 parent 8bcb2c5 commit a26bfd9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions tests/Issues/InlineTags/Fixture/with_description.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
27 changes: 27 additions & 0 deletions tests/Issues/InlineTags/Fixture/with_punctuation.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use PHPUnit\Framework\TestCase;

/**
* @copyright Some Value. Something.({@link https://example.com}).
* @covers \Tests\BarController
*/
class WithDescription extends TestCase
{
}

?>
-----
<?php

use PHPUnit\Framework\TestCase;

/**
* @copyright Some Value. {@link https://example.com}.
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\Tests\BarController::class)]
class WithDescription extends TestCase
{
}

?>

0 comments on commit a26bfd9

Please sign in to comment.