-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
[2.x/3.x] Add matchNotNull and other *NotNull implementations #14
Conversation
@glaubinix probably something you want to take a look at too. |
src/NotNullMatchResult.php
Outdated
* @param 0|positive-int $count | ||
* @param array<string> $matches | ||
*/ | ||
public function __construct($count, array $matches) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should have a int
parameter type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, looks like I forgot the result classes when working on the initial 2.0 changes. Will fix this.
While it seems clear in isolation, in practice it starts getting a bit nightmarish (to me, anyway). For example, when reading Now |
😆 hence why I asked. Strict sounds ok too. But to be honest I think we also could omit a few, like the WithOffsets ones, because they are less commonly needed and so it's not that bad if you have to check for nulls sometimes. But the isMatch and other common ones trigger 150 errors in the Composer codebase alone.. |
Yes, that seems reasonable. It would also make the Perhaps |
Yeah I think I like StrictGroups, it's descriptive at least. For sure it'll confuse at first but that's probably the case no matter the name here given it's kind of a small distinction. |
… nullable matches
I'd be happy for a sanity check here before proceeding and adding the rest of them (matchWithOffsetsNotNull, matchAllNotNull, matchAllWithOffsetsNotNull, replaceCallbackNotNull, replaceCallbackArrayNotNull, isMatchNotNull, isMatchAllNotNull, isMatchWithOffsetsNotNull, isMatchAllWithOffsetsNotNull 😅 ).
The issue is that due to the improvements in PHPStan and https://github.com/composer/pcre/releases/tag/3.0.2 you now get errors everywhere because
$match[1]
for ex isstring|null
even tho in many cases the null will never happen. This is however dependent on the pattern and thus cannot really be asserted easily in the types.So adding these NotNull variants for all functions outputting nullable matches solves this by letting you opt in to stricter non-nullable types, and if you messed up and your pattern does have null/unmatched-subpatterns you get an exception.
The main problems I see and where I'd love feedback are:
/cc @johnstevenson @naderman @stof