Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 16, 2025

Conversation

samsonasik
Copy link
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
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
41 checks passed
@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
Member Author

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

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

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

@samsonasik
Copy link
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants