Skip to content

[BetterPhpDocParser] Use str_starts_with() and str_ends_with() over str_contains() on DoctrineAnnotationDecorator#6671

Merged
samsonasik merged 2 commits intomainfrom
use-str-starts-end
Jan 16, 2025
Merged

[BetterPhpDocParser] Use str_starts_with() and str_ends_with() over str_contains() on DoctrineAnnotationDecorator#6671
samsonasik merged 2 commits intomainfrom
use-str-starts-end

Conversation

@samsonasik
Copy link
Copy Markdown
Member

@samsonasik samsonasik commented Jan 16, 2025

@andrewnicols continue of your PR:

I am thinking that str_ends_with() and str_starts_with() can be used over str_contains(), which seems should only cover start and last over the whole token for more precise check, ensuring it not just part of some "string".

@samsonasik
Copy link
Copy Markdown
Member Author

All checks have passed 🎉 @TomasVotruba I am merging it to have faster feedback to test ;)

@samsonasik samsonasik merged commit 354ef50 into main Jan 16, 2025
@samsonasik samsonasik deleted the use-str-starts-end branch January 16, 2025 10:03
@samsonasik samsonasik changed the title [BetterPhpDocParser] Use str_starts_with() and str_starts_with() over str_contains() on DoctrineAnnotationDecorator [BetterPhpDocParser] Use str_starts_with() and str_ends_with() over str_contains() on DoctrineAnnotationDecorator Jan 16, 2025
@samsonasik
Copy link
Copy Markdown
Member Author

@andrewnicols please test latest "rector/rector": "dev-main" and verify if it still works :)

@andrewnicols
Copy link
Copy Markdown
Contributor

Alas, it does not.

It works for the case where the doc is:

* @copyright Example {@link https://example.com}

But if there is anything immedaitely after the curly brace, for example a {{.}}:

* @copyright Example {@link https://example.com}.

Then it no longer works. Changing back to {{str_contains}} gets it back to passing.

@samsonasik
Copy link
Copy Markdown
Member Author

@andrewnicols thank you for verify, I will check.

andrewnicols added a commit to andrewnicols/rector-src that referenced this pull request Jan 16, 2025
…or (rectorphp#6671)

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.
@andrewnicols
Copy link
Copy Markdown
Contributor

I've created #6674 with a demo and more tests.

@samsonasik
Copy link
Copy Markdown
Member Author

@andrewnicols you're fast, thank you 👍

samsonasik pushed a commit that referenced this pull request Jan 16, 2025
…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.
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants