Now that you have your Rector properly configured with your customization, either via MLP or custom code you can continue with a dry-run or run rector automatically.
Dry-run Rector
Dry-run gives you the opportunity to see what Rector has found and will execute/change before it actually does it on your behalf.
it's time to dry-run rector by executing the following command.
cd /path/to/sugar && rector-0.15.24/bin/rector process --clear-cache --dry-run > php82.diff
Dry run produces a very detailed output file (if you spooled it off to a file) containing the diff and the list of rector rules that were applied to make your code compatible with PHP 8.2 (which we configured it to)
1 file with changes =================== 1) custom/Extension/application/Ext/Include/BuildingBlock_HelloWorldDashlet.php:0 ---------- begin diff ---------- @@ @@ <?php //WARNING: The contents of this file are auto-generated - $this->ss->assign("current_users", count($active_users)); - $this->ss->assign("user_count_param", "user_count: '".count($active_users)."'"); + $this->ss->assign("current_users", is_countable($active_users) ? count($active_users) : 0); + $this->ss->assign("user_count_param", "user_count: '".(is_countable($active_users) ? count($active_users) : 0)."'"); ?> ----------- end diff ----------- Applied rules: * AddDefaultValueForUndefinedVariableRector (https://github.com/vimeo/psalm/blob/29b70442b11e3e66113935a2ee22e165a70c74a4/docs/fixing_code.md#possiblyundefinedvariable) * CountOnNullRector (https://3v4l.org/Bndc9) [OK] 1 file would have changed (dry-run) by Rector
Execute Rector
If your dry-run is clear or you are ready to let Rector auto-update your code, now it's time to get a second git commit to "clear" the system so we know exactly what rector has done to our system.
Prepare Git
sh-3.2$ git status On branch main Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: config_override.php modified: custom/application/Ext/Include/modules.ext.php Untracked files: (use "git add <file>..." to include in what will be committed) custom/Extension/application/Ext/Include/BuildingBlock_HelloWorldDashlet.php custom/Extension/application/Ext/Include/orderMapping.php custom/clients/ custom/modules/ActivityStream/ custom/modules/Forecasts/Ext/clients/ custom/modules/pmse_Project/ no changes added to commit (use "git add" and/or "git commit -a")
Commit
sh-3.2$ git add . && git commit -am "Before Rector" [master 33a18416] Before Rector 422 files changed, 96500 insertions(+)
Execute
Run the rector process once again, but without --dry-run
and --clear-cache
options as the cache is up to date (the process should look like this):
➜ sugar git:(master) rector-0.15.20/bin/rector process 10/30 [▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░] 33%
After Execution (Git diff)
sh-3.2$ git status On branch main Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: custom/Extension/application/Ext/Include/BuildingBlock_HelloWorldDashlet.php no changes added to commit (use "git add" and/or "git commit -a")
sh-3.2$ git add . && git commit -am "PHP 8.2 upgrade refactor" [master 7ad3bf22] PHP 8.2 upgrade refactor 1 files changed, 1 insertions(+), 1 deletions(-)