# Automated Refactoring ## Phase 1: Manually re-factoring modules - Check out a module - Create feature branch for PHP8.1 refactoring - Configure Rector - Run Rector on it - Commit and PR - Update Repman (does this happen automatically?) ### Check out a module https://bitbucket.org/elementarydigital/magento2-module-product-label/src/master/ ### Create feature branch for PHP8.1 refactoring Check out a new feature branch in the module directory: ```shell git checkout -b php81-refactoring HEAD -- ``` ### Configure Rector - Install Rector - Add it as a `composer require --dev` dependency to the project (or install it globally) - Configure Rector for PHP and Magento 2 - Create a `rector,php` file in the root of the module directory - Where to find Magento 2 specific rectors? - Magento coding standard (`magento/magento-coding-standard`) - Consider configuring Rector for other things e.g. PHPUnit! - https://github.com/rectorphp/rector-phpunit ### Run Rector ```shell php81 /var/www/html/rector/vendor/bin/rector process \ --config /var/www/html/wearemagneto/projects/hstv/html/rector.php \ --autoload-file /var/www/html/wearemagneto/projects/hstv/html/vendor/autoload.php \ /var/www/html/wearemagneto/projects/hstv/html/app/code/Mapp/Connect/Test/Unit/Setup/Patch/Data/DisableForSilverSurfersStoreTest.php ``` ### Commit and PR changes (if any) Commit to the feature branch, push and create a new PR in Bitbucket. Tag in other developers for visibility and to solicit feedback. Once the PR has been approved, merge to master and tag the commit with an update release version number. Repman will then automatically update the package and make the new version available in composer. ## Phase 2: Automation - Build a workflow to automate these steps, possibly using Deployer