Instant Upgrades and Instant Refactorings for PHP Applications. Why do it manually?
#rectorphp
Created by @votrubaTgetrector.com/hire-team PHP CommunityJoined December 2018
Rector 2.5 came with unused skips feature to cleanup your configs.
Run Rector on the whole project, without cache, to get the results:
vendor/bin/rector --clear-cache --dry-run
But how does it look like on a real project?
Here in Mautic we removed 45 lines from rector.php ⬇️
github.com/mautic/mautic/…
Much readable 😊
🧹 @rectorphp 2.5 is out!
New: ->reportUnusedSkips() - like PHPStan's reportUnusedIgnores, but for your skip config.
Stale skips rot silently. Now Rector tells you which ones never matched:
[WARNING] This skip is unused, it never matched any element.
* SimplifyUselessVariableRector => */NonexistentUnused/*
Clean config, free 😎
Just extract typical dev's workflow:
1) Pick an issue most likely to be fixed, while also bringint a value to the user
2) Extract reproducer test
3) Try to fix it, give it 10 min max (always enough for our issues, just to avoid to open-defined issues that make not enough sense)
4) open PR
5) make CI pass, give it 10 mins max
6) ping me once done or overtime
7) goto 1)
8) do max 1 issue per 20 mins (so I can review or improve this loop)
I used agent this way to fix 40 out of 50 issues through my 20 repositories in a work week.
While having fun, not going crazy and adding few features on the go.
I am pretty skeptical of building loops for everything because I'm paranoid about the agents creating slop if I'm not there to monitor what they're doing.
What are some good loops to try for coding or regular knowledge work?
I'll share thoughts behind the question...
If it's a tool, I don't know like PHPUnit, PHPStan, ECS, other coding standard tools or @rectorphp, there is a high chance its installed in couple thousands of open-source projects.
Now the data mining part:
1) if it's in these projects, we can see it installed in composer.json
2) then we can see a config
3) in the config, there is first user's feedback
4) not all bugs reach project's issue tracker
5) we find let's say top 100 repositories on GitHub that use our project
6) then we check config for any ignore/skip/commented out behavior of our tool
7) behavior that should work, but it doesn't
8) it can look like:
// Skip, false positive
// Unreadable change
// Breaks
9) then we extract this line, typically bound to specific file
10) then we ask our agent to check if it's edge case behavior or a bug
11) 3 out of 4 will be bugs
12) if it's considered bug by our agent, we ask him to fix it
13) then create a PR to our tool and make CI pass, cover with test fixture of course
14) the test fixture is already provided in GitHub repository skip line
15) make CI pass and merge
16) find next skipped line, repeat
17) once a month, release a new version of your tool and send PR to each repository where it fixes a skip
18) repeat untill all unreported bugs are fixed on top 1000 repositories on GitHub
19) there is high chance we've just fixed dozens or even hundreds of bugs that would never be reported, but all open-source and private projects can benefit from
20) 100 % automated with scripts + agents
21) profit 👌☺️
A nice thread running through one of the @LaravelLiveUK talks this morning - the "closed by default" principle, and a tour through how PHP has quietly become a much stricter, safer language since 5.0.
Less permissive. Less error-prone. Better tooling. @rectorphp, Pint, @phpstan doing a lot of the heavy lifting. And if you haven't looked at the Type Coverage plugin for PHPStan or the rector-laravel package - both are worth your time, trust me!
PHP's reputation hasn't always caught up with where the language actually is. Talks like we've seen this morning are a good reminder of how far it's come
I've just bumped @rectorphp dev repository PHP version PHP 8.4 to enjoy latest syntax.
But you can still used it on PHP 7.4+ as a dependency 😉
How?
tomasvotruba.com/blog/scope-and…
(This trick comes handy for any codebase that needs an upgrade)
🚀 Rector 2.4.6 is out!
✨ New RenameDeprecatedMethodCallRector - auto-renames calls from your @deprecated docblocks
✨ Brand new named args set
✨ Symfony 8 support enabled in composer-based
🐛 Many crash & dead-code fixes
github.com/rectorphp/rect…#php#rector#refactoring
🚀 Rector 2.4.6 is out!
✨ New RenameDeprecatedMethodCallRector - auto-renames calls from your @deprecated docblocks
✨ Brand new named args set
✨ Symfony 8 support enabled in composer-based
🐛 Many crash & dead-code fixes
github.com/rectorphp/rect…#php#rector#refactoring
Using an agent...
....what custom @rectorphp rule or @phpstan extension/rule have you created,
that you would not have the nerves and the time to create manually?
Do you have a rule set for your community/package?
Consider adding composer-based sets and register them to @rectorphp core
That way, these rules are loaded automatically based on composer.json versions
@drupal set coming soon...
github.com/rectorphp/rect…
Would you merge such a PR without deep review of all ~300 files?
We do. Because it's not AI, nor human.
It's tokens (T_*, not AI) and AST. 100 % trust, 0 % hallucinations
I've just realized we didn't have an offical way to sponsor @rectorphp ... Fixed it first task today ⬇️
If you're a company using Rector and saving you time and money, consider giving back to support on-going development🙏
github.com/sponsors/recto…
Symplify PHPStan rules 14.11.0 just dropped 🎉
2 lines in your phpstan.neon, two new safety nets:
* ctor: true # use constructors, not setter soup
* mocks: true # spot fragile PHPUnit mocks
Bonus: smarter return types for Symfony, Laravel & path functions - now built in.
PHP 8.4 ✅
Check the full release with examples ⬇️
github.com/symplify/phpst…
Rector is now on GitHub Sponsors! 🎉
Rector upgrades and refactors PHP, frameworks and keeps technical debt away💙
Work that takes attention and time, done automatically: in CI or CLI, for free
If Rector saves your team time, consider sponsoring its development:
👉 github.com/sponsors/recto…
Your sponsorship keeps it free, open, and actively maintained 💙
PHPStan core is just the start. I built a searchable index of 263 community @phpstan rules from 11 popular packages - each with its class name, what it catches, and wrong/correct examples.
Goldmine for tightening your PHP codebase 👇 tomasvotruba.com/phpstan-rules-…
6K Followers 35 Following✍️ Writing a book about final solution to legacy https://t.co/ffWET1OvFW
😎 Upgrading PHP legacy projects
🤖 Automating PHP code with @rectorphp
4K Followers 1K FollowingSenior PHP Engineer via @ExploreAdeva | Building @codysseydev | Sharing Software Architecture and Design tips and tricks with PHP
1K Followers 369 Following🇵🇱 https://t.co/HerX32NWvo 🇬🇧 https://t.co/m6h4mNhOBh | Self-educated specialist: PHP, CI/CD, QA automation, Docker, Gitlab and more 😎. Member of @PHPCSFixer team 🪶.
6 Followers 43 FollowingEngineering at @BondForge_HQ
APIs, SDKs, and systems built to survive real-world conditions.
We argue about edge cases so you don’t have to. 🔨
4 Followers 80 FollowingI'm Alexandro COCOUVI, but you can simply call me Xandro 😄. I'm a Full-Stack Developer with a strong specialization in backend development.
95 Followers 5K FollowingMe gustan, la tecnología, los gadgets, el diseño inteligente. Amo: el basquetbol; cocinar; internarme un día entero en el cine; mi familia
263 Followers 2K FollowingHi, I'm a software developer with a passion for solving problems and building innovative solutions. I specialize in Backend Dev, looking for new challenges #web
1 Followers 61 FollowingPHP & high-performance systems lab. Exploring architectural limits by deconstructing and rebuilding web software from the ground up to scale under massive loads
6K Followers 35 Following✍️ Writing a book about final solution to legacy https://t.co/ffWET1OvFW
😎 Upgrading PHP legacy projects
🤖 Automating PHP code with @rectorphp