Skip to content

[DX] Add ->withPhpXSets() for PHP 7.4 and lower, improve ->withPreparedSets()#5984

Merged
TomasVotruba merged 6 commits intomainfrom
tv-named-arg-config
Jun 20, 2024
Merged

[DX] Add ->withPhpXSets() for PHP 7.4 and lower, improve ->withPreparedSets()#5984
TomasVotruba merged 6 commits intomainfrom
tv-named-arg-config

Conversation

@TomasVotruba
Copy link
Copy Markdown
Member

@TomasVotruba TomasVotruba commented Jun 20, 2024

The withPhpSets() method uses named arguments, available since PHP 8.0.
If you use Rector on PHP 7.4 and lower, it can be confusing to use:

return RectorConfig::configure()
     ->withPhpSets(false, false, false, true);

That's unreadable and error prone. Once new version or order is changed, it behaves differently.


Instead, this PR introduces clear method API:

return RectorConfig::configure()
     ->withPhp73Sets();

✔️

Nice and clear :)


Ideally, the withPhpSets() should be used without any argument, so it always follows your composer.json version 👍

@TomasVotruba TomasVotruba force-pushed the tv-named-arg-config branch from 66d345d to b6dc174 Compare June 20, 2024 07:47
@TomasVotruba TomasVotruba changed the title tv named arg config [DX] Add ->withPhpXSets() for PHP 7.4 and lower Jun 20, 2024
@TomasVotruba TomasVotruba force-pushed the tv-named-arg-config branch 2 times, most recently from 0293ca5 to f7b13c6 Compare June 20, 2024 07:58
@TomasVotruba TomasVotruba changed the title [DX] Add ->withPhpXSets() for PHP 7.4 and lower [DX] Add ->withPhpXSets() for PHP 7.4 and lower, improve ->withPreparedSets() Jun 20, 2024
@TomasVotruba TomasVotruba force-pushed the tv-named-arg-config branch from cf59c26 to 3836a57 Compare June 20, 2024 13:00
Copy link
Copy Markdown
Member

@samsonasik samsonasik left a comment

Choose a reason for hiding this comment

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

RemovePhpVersionIdCheckRector should be skipped for Notifier file

@TomasVotruba TomasVotruba requested a review from samsonasik June 20, 2024 13:01
@TomasVotruba
Copy link
Copy Markdown
Member Author

Ready for next review 👍 :)

@TomasVotruba TomasVotruba force-pushed the tv-named-arg-config branch from 3836a57 to e02e9d9 Compare June 20, 2024 13:02
Copy link
Copy Markdown
Member

@samsonasik samsonasik left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@TomasVotruba
Copy link
Copy Markdown
Member Author

Thank you 👏

@TomasVotruba TomasVotruba merged commit afdf525 into main Jun 20, 2024
@TomasVotruba TomasVotruba deleted the tv-named-arg-config branch June 20, 2024 13:17
// suitable for PHP 7.4 and lower, before named args
public function withPhp53Sets(): self
{
Notifier::notifyNotSuitableMethodForPHP80(__METHOD__, 'withPhpSets');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The warning seems shown multiple times due to parallel:

 [WARNING] The "Rector\Configuration\RectorConfigBuilder::withPhp53Sets()"      
           method is suitable for PHP 7.4 and lower. Use "withPhpSets()" method 
           instead.                                                             
                                                                                

  0/99 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%
                                                                                
 [WARNING] The "Rector\Configuration\RectorConfigBuilder::withPhp53Sets()"      

           method is suitable for PHP 7.4 and lower. Use "withPhpSets()" method 
           instead.                                                      
                                                                                
 [WARNING] The "Rector\Configuration\RectorConfigBuilder::withPhp53Sets()"      
           method is suitable for PHP 7.4 and lower. Use "withPhpSets()" method 
           instead.                                                             
                                                                              
                                                                                
 [WARNING] The "Rector\Configuration\RectorConfigBuilder::withPhp53Sets()"      
           method is suitable for PHP 7.4 and lower. Use "withPhpSets()" method 
           instead.                                                        

that can't be tweak here, only on ApplicationFileProcessor level, the single warning can be shown...

Also, I am thinking if github workflow uses:

      matrix:
        php-versions: ['7.4, '8.0']

that may not suit, so probably suggest to use withSets()...

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