- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
PhpdocToReturnTypeFixer - fix for breaking PHP syntax for type having reserved name #4963
PhpdocToReturnTypeFixer - fix for breaking PHP syntax for type having reserved name #4963
Conversation
I would prefer not having to maintain that list over time. Maybe we could have a way to detect that automatically, e.g. https://3v4l.org/OCU5L: function is_valid_type($type) {
try {
return true === eval("function ({$type} \$arg) {}; return true;");
} catch (ParseError $exception) {
return false;
}
} Hacky but way simpler. |
Shouldn't be time-consuming to keep the list up to date - how often new tokens are added to PHP? Every new "major" release - and we would, of course, automate that. Approach with P.S. pinging @Slamdunk for an opinion as the author of fixer. |
I think the best place would be somewhere within the For maintaining the list; maybe we can have test that fails if you run the tests on a PHP major version higher than we know is complete for the list. Than on the failure we can update the list and update the test, something like that? |
While I appreciate the clean idea of @kubawerlos , as I get older I have less and less spare time to give to FOSS projects, and I guess everyone will have the same issue in the long run. I'd like to invest my (and your) time in a activities with more values, like fixers for new syntax in the upcoming PHP versions. So I'd go for @julienfalque solution: it seems to me easy to implement, future proof and with low performance impact since it can be easily cached if needed. |
for me |
Thank you @kubawerlos. |
…pe having reserved name (kubawerlos) This PR was squashed before being merged into the 2.16 branch (closes #5006). Discussion ---------- PhpdocToParamTypeFixer - fix for breaking PHP syntax for type having reserved name Twin PR to #4963 I wonder if it would be useful to have some class e.g. `SyntaxChecker` with (static?) method `isValid`, which will handle cache internally and all needed will be to call it like this: ```php if (!SyntaxChecker::isValid(sprintf('<?php function f(%s $x) {}', $returnType))) { continue; } ``` Currently, this will have 2 uses (here and `PhpdocToReturnTypeFixer`, maybe also `AbstractPsrAutoloadingFixer`, not mandatory), but I imagine quite soon we will have `PhpdocToPropertyTypeFixer`. Commits ------- 76dde6f PhpdocToParamTypeFixer - fix for breaking PHP syntax for type having reserved name
This test tries all tokens as return type which results with 73 failures.
Limiting test to PHP 7.4 is only because of laziness - finally, it should run for all PHP versions.
A question to @keradus, @SpacePossum and @julienfalque: do you think we
php-cs-fixer/all-token
to provide us with all tokens to test like this