Consider warning user when PHP runtime doesn't fit lowest PHP version from composer.json #7312
Replies: 3 comments 8 replies
-
It sounds like a good idea. Specific fixers shouldn't be aware of Composer's context, but main process could determine PHP requirement and print some warning. I would even consider failing the process if it happens, because people don't read the warnings 😉. |
Beta Was this translation helpful? Give feedback.
-
What about introducing an environment variable, e.g. This variable would also allow us to prevent introducing changes that are not compatible with some old PHP version, even if the tool itself does not support running on that version anymore. However I guess that would also mean adding a lot of test cases. |
Beta Was this translation helpful? Give feedback.
-
Regarding the PHP version resolution The most secure would be to require setting the PHP version in the config file, because falling back to the runtime version is not secure as it requires the user to remember about the runtime the tool is running in when fixing the code. Theoretically this required config option could be considered a BC Break and require major version release because after upgrading a tool it will fail. However I don't think that failing at the beginning with information about missing config value should be considered a BC Break. Especially for tool that is used only in CI, not in production. Second option and I think most popular around such tools would be to fall back to the PHP runtime version. Most of the projects install php-cs-fixer as a dev dependency and run in the same PHP runtime as the application. However some project run php-cs-fixer as e.g. docker image for various of reasons with the most valuable being a chance to use newer version of the tool (new features, bugfixes) while application runtime is locked on lower one. If this is a case then one has to remember to set php version in the config. Regarding applying fixer (or a part of a fixer) with changes no compatibile with the PHP version IMO fixer should ignore features that do not exist in the targeted PHP version. There's no need to throw. We could display warning at the end .e.g.
We could also consider adding cli option to control whether to fail or not on such warnings. |
Beta Was this translation helpful? Give feedback.
-
if project XYZ supports
php: ^7 || ^8
and one would run PHP CS Fixer on PHP 8.2, they could apply code changes that won't be valid for PHP 7.0.idea: maybe we should warn user that they run it on high version and they should consider running the tool on lowest supported PHP of their repository?
Beta Was this translation helpful? Give feedback.
All reactions