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

ExplicitNullableParamTypeRector can be applied from PHP 7.1 #5848

Closed

Conversation

GromNaN
Copy link

@GromNaN GromNaN commented Apr 29, 2024

PHP 8.4 deprecates implicit nullable parameters, but the transformation can be applied with PHP 7.1+ compatibility.

This change is necessary in order to use the ExplicitNullableParamTypeRector with projects that allows PHP < 8.3 (i.e. all projects that currently exist), to make them compatible with PHP 8.4.

@@ -75,6 +75,6 @@ public function refactor(Node $node): ?Param

public function provideMinPhpVersion(): int
{
return PhpVersionFeature::DEPRECATE_IMPLICIT_NULLABLE_PARAM_TYPE;
Copy link
Author

@GromNaN GromNaN Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constant becomes unused, but is part of the API, I don't know if you want to keep it.

@GromNaN
Copy link
Author

GromNaN commented Apr 29, 2024

Here's how I used this rule to create this PR felixfbecker/php-language-server-protocol#22

Install rector:
composer require --dev rector/rector

Setup the config with only one rule:

<?php

return Rector\Config\RectorConfig::configure()
    ->withPaths([__DIR__ . '/src'])
    ->withRules([Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector::class]);

And run vendor/bin/rector.

Without change, nothing is fixed since the project requires php >= 7.1.

@samsonasik
Copy link
Member

I don't want to enforce something that not deprecated to begin with, so it needs to be php 8.4.

Feel free to copy and modify as your own custom rule.

Thank you for understanding.

@samsonasik samsonasik closed this Apr 29, 2024
@GromNaN
Copy link
Author

GromNaN commented Apr 29, 2024

Please read my comment. The rule can't be applied to projects that support PHP 8.4.
I think it's a bad strategy to ask everyone to fork the rule when there are hundreds of libraries to fix and rector is the best tool for that.

Maybe there is an other solution to allow using this rule without enforcing it.

@samsonasik
Copy link
Member

Php 8.4 is not yet released, however, you should can enforce via config:

->withPhpVersion(PhpVersion::PHP_84)

@GromNaN
Copy link
Author

GromNaN commented Apr 29, 2024

Ok, thanks for that clarification.

@samsonasik
Copy link
Member

No worries, btw, the better way is to create new release and new compatible code once php 8.4 released, that's ensure nothing left behind, and not accidentally applied syntax that not yet supported.

@GromNaN
Copy link
Author

GromNaN commented Apr 29, 2024

The "new" syntax is supported since PHP 7.1, which is 8 years old. Most of the actively supported libraries already dropped older PHP versions.

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