Skip to content

Instantly share code, notes, and snippets.

@ProcessEight
Last active May 3, 2024 20:34
Show Gist options
  • Select an option

  • Save ProcessEight/6238fcc9810565957184862e40d0172a to your computer and use it in GitHub Desktop.

Select an option

Save ProcessEight/6238fcc9810565957184862e40d0172a to your computer and use it in GitHub Desktop.
Discussion of automated refactoring processes to bring legacy codebases up to date

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:

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!

Run Rector

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
@MagePsycho
Copy link

Do you mind sharing the rector.php file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment