rector-src icon indicating copy to clipboard operation
rector-src copied to clipboard

[PHP8.3] add new rectors for get_class()/get_parent_class() without arguments

Open cabbey opened this issue 1 year ago • 6 comments

This adds two new rules to the PHP8.3 collection for replacing the newly deprecated calls to get_class() and get_parent_class() without passing an object argument to them.

I choose to use __CLASS__ as the replacement for get_class() as it has wider support, going back to 5.0, than the alternative of self::class, which only goes back to 5.4.

I choose to use parent::class as the replacement for get_parent_class() as it felt like the most direct logical mapping.

These are also my first rectors, I welcome feedback on them. (I have since writing these a couple months back written a few more significantly more complex ones that are unique to our codebase, these were my first foray to learn how they work.)

cabbey avatar Oct 30 '24 17:10 cabbey

You need to rebase latest main branch to fix unit test:

git checkout main
git pull [email protected]:rectorphp/rector-src.git main
git checkout add-get-class-rectors
git rebase main
git push --force origin add-get-class-rectors

samsonasik avatar Oct 30 '24 17:10 samsonasik

You need to rebase latest main branch to fix unit test:

git checkout main
git pull [email protected]:rectorphp/rector-src.git main
git checkout add-get-class-rectors
git rebase main
git push --force origin add-get-class-rectors

ugh, I just realized I keep git pulling and it's pulling from my fork on git hub instead of the correct upstream... no wonder things haven't changed all week. 🤦 Will get this rebased shortly.

cabbey avatar Oct 30 '24 18:10 cabbey

even with the correct main pulled (d246d27a9442cc08a419e899e07c2c19a680eb80), still a failure in an unrelated test, both on main and on my rebased branch:

1) Rector\Tests\Issues\AutoImport\AutoImportTest::test with data set #1 ('/Volumes/Git/rector-src/tests...hp.inc')
Failed on fixture file "doctrine_deep_annotation.php.inc"
...

cabbey avatar Oct 30 '24 18:10 cabbey

composer update :)

samsonasik avatar Oct 30 '24 18:10 samsonasik

TA-DA! all clean on both main and my branch now. Thanks for that tip!

I guess I'm spoiled by having all of our repos at work automatically do that whenever git detects a change to the composer.* files. :)

cabbey avatar Oct 30 '24 18:10 cabbey

converting to draft while I re-work the rules... may take a few days given my other workload.

cabbey avatar Oct 30 '24 19:10 cabbey

Thank you :partying_face:

TomasVotruba avatar Nov 04 '24 22:11 TomasVotruba