When using a Swiss knife, we think of a tool with many practical abilities. They're useful for different situations we might experience in the wild. Opening a box of milk? Here is a knife. Cutting wood to start a fire? Here is a chainsaw. Are the letters on the paint bucket too tiny? Try this magnifying class. Now, we apply the...
When I come to a new project, I want to make a rough idea of what I'm dealing with in a few minutes. I usually check composer.json and measure the lines. Then, I'd love to run PHPStan and get a rough idea of the current state. But are there baselines, custom extensions, global ignores, or no PHPStan at all?
...and how to avoid it. Type coverage is a way to gradually add type declarations to your PHP project—step by step, one by one. It's a PHPStan package that helps you maintain a specific minimal level from 0 % to 100 %. Once we reach high coverage of 80-90 %, we feel safer. But our code can actually be in worse, even dangerous,...
When we upgrade a new project to the best version possible, the latest PHP and framework versions, it's not only about changing syntax sugar to a more fancy one. It's about the vast focus shift in project management so far. It's a change to master. I want to share the basic rules we apply to make the "impossible" upgrades...
I'm happy to introduce the latest update to our book - Rector, the Power of Automated Refactoring, along with Rector version 0.19.5 from this week. This release includes 2 new commands, brand new configuration with smart IDE autocomplete, brand new chapter and DX improvements to help you master code refactoring with ease.
In the first post, we looked at the long-term effects of our decisions. Turning a legacy project into a fresh one is a matter of the "just do it" approach. But there are 3 things we should take with care even if our project seems outside the legacy project category. The second of those is mocks.
Early this year, I created a few custom Rector rules for our client. It modified the code based on the PHPUnit error result report. The only problem is that PHPUnit outputs a string. So, I had to parse it manually with regexes. Having a JSON output would make my life easier. I'm used to PHP tools that provide the JSON out of the...
In the first post, we looked at the long-term effects of our decisions. Turning a legacy project into a fresh one is a matter of the "just do it" approach. But there are 3 things we should take with care even if our project seems outside the legacy project category. First of those are arrays.
Do you work with Symfony since 2 through 7? Then you know the main challange in the upgrade path is to trim your YAML configs to minimum. Where we needed 300 lines in YAML configs, we now need 2 lines. How to get there fast and reliable? I'll show 3 trick we use in Symfony project to get there.
The famous phploc package to measure project size was archived by Sebastian on Jan 10, 2023. I used this package to get feedback on CLI apps vendor shrink and for fast estimation of project size in Rector upgrades. That's why I needed a replacement. Fast!
Final classes have many great benefits for future human readers of your code. They have even more benefits for static analysis and Rector rules. But what if we have a project with 1000+ classes and 10 minutes and want to automate the finalization process safely?
I have a couple of open-source CLI apps like Rector, ECS, Class Leak, Config Transformer, Monorepo Builder and Lines, and private ones like Cleaning Checklist, Fixai, Private Rector and Entropy. All of them run in the command line, and some of them are downgraded to PHP 7.2. In every project, there is the rule, the fewer...