Basic Setup
You will need a basic setup to have Rector working with Sugar. We will create files and initialize a git repo in the Sugar instance folder to keep track of the changes.
If you are using a pre-existing instance, keep that in mind, we suggest creating a new instance for this purpose.
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 // ]); };