Basic Setup
Refactoring your code required a very basic setup to make your life easier to track what Rector does to your code (if you use its auto-fix mode).
Basic setup means installing software you will need such as Rector and Git. Git will help us to keep track of changes in your Sugar instance folder after we initialize it.
Keep that info in mind if you are planing to use a pre-existing instance for this work, it will add a lot of extra files to it.
Step by Step
- Download a build of SugarCRM. Please use the one that is compatible with your MPL.
- Install the build locally or use your own Sugar instance if you have one local
- Download the latest rector release and unzip it into the Sugar instance folder. ex:
/path/to/sugar/rector-0.15.20
- Rector needs
phpstan
tool to run, for that create a new file in the Sugar instance folder calledstan.neon
. ex:/path/to/sugar/stan.neon
parameters:
level: 1
bootstrapFiles:
- include/entryPoint.php
- Initialize a git repository inside the instance folder: cd /path/to/sugar && git init. It’s just convenient to use git to track the list of files and some other things.
- Create /path/to/sugar/.gitignore file to skip the unneeded changes with the following contents:
cache
vendor
portal2
upload
upgrades
*.log
rector.php
- Commit the initial repository state
git add . && git commit -am 'init'
- Initialize rector config:
cd /path/to/sugar && rector-0.15.20/bin/rector init
-
Agree to create a rector.php file with the dummy config. It should generate a template file similar to this:
<?php
declare(strict_types=1);
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/Ext',
//... more subdirs here
__DIR__ . '/upgrades',
]);
// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
// define sets of rules
// $rectorConfig->sets([
// LevelSetList::UP_TO_PHP_74
// ]);
};