Skip to content

ExplicitNullableParamTypeRector can be applied from PHP 7.1#5848

Closed
GromNaN wants to merge 1 commit intorectorphp:mainfrom
GromNaN:nullable-type-minimum-php-version
Closed

ExplicitNullableParamTypeRector can be applied from PHP 7.1#5848
GromNaN wants to merge 1 commit intorectorphp:mainfrom
GromNaN:nullable-type-minimum-php-version

Conversation

@GromNaN
Copy link
Copy Markdown

@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.


public function provideMinPhpVersion(): int
{
return PhpVersionFeature::DEPRECATE_IMPLICIT_NULLABLE_PARAM_TYPE;
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

->withPhpVersion(PhpVersion::PHP_84)

@GromNaN
Copy link
Copy Markdown
Author

GromNaN commented Apr 29, 2024

Ok, thanks for that clarification.

@samsonasik
Copy link
Copy Markdown
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
Copy Markdown
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.

@GromNaN
Copy link
Copy Markdown
Author

GromNaN commented Apr 29, 2024

@GromNaN GromNaN deleted the nullable-type-minimum-php-version branch September 25, 2024 17:46
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