SugarClub
SugarClub
  • User
  • Site
  • Search
  • User
  • Groups & Discussions
    Groups & Discussions
    • Product Forums
      Product-focused Q&A, discussions, best practices, fixes, and help
      Product Forums
      • Sugar Market
      • Sugar Sell & Enterprise
      • Sugar Serve
      • sales-i
    • User Groups
      Professional, Industry, Language
    • Get Involved
      Learn how to become a SugarCRM Ambassador
    • Social Club
      Live, interactive, virtual meetups with other Sugar customers and Sugar’s Subject Matter experts!
    • Leadership Lounge
      Network with fellow organizational leaders, ask questions, and share insights
    • Developers
      Visit DevClub, the SugarClub group for Sugar Developers
      Developers
      • DevClub
      • Mobile Developers
      • Developer Builds
        Supplemental access level required. Inquiries: developers@sugarcrm.com
    • Additional Groups (Access Required)
      Groups that require special access will be displayed here. Contact sugarclub@sugarcrm.com for assistance. Click here to see all groups
      Additional Groups (Access Required)
      • SugarCloud Platform
  • Product Information
    Product Information
    • Release Central
      Find release-specific content to prepare for your next Sugar update
    • Documentation & Resources
      Looking to expand your Sugar knowledge? Explore our in-depth documentation and other helpful resources!
    • Product Update Blogs
      Updates about each Sugar product
    • Customer Stories »
      Case Studies by SugarCRM
  • Training & Certification
    Training & Certification
    • Training & Certification Home
      Live & On-Demand classes, Quick Videos, Sugar Certifications, and more!
    • Quick Videos
      Short videos about using Sugar
    • Event Recordings
      Recordings from SugarU Live Webinars and Sugar Market Academy
    • My SugarU Dashboard »
    • SugarU News & Updates
  • Adoption
    Adoption
    • Grow Adoption Framework
      Get started on your adoption journey and review the adoption resources from SugarCRM
  • Calendar
  • News
    News
    • Sugar News
    • SugarCRM.com News »
    • Dev Blog
    • SugarCRM Marketplace Blog
  • Help
    Help
    • Welcome to Sugar!
      New to Sugar? Get started here!
    • SugarClub Help & Instructions
      Learn more about SugarClub and find answers to questions about this site
    • New to SugarClub?
      Start your community journey here
    • Technical Support
      Sugar's support resources
      Technical Support
      • Case Portal »
        Access the SugarCRM Case Portal
      • Working with Sugar Support »
        Find out more about engaging with the SugarCRM Support team
      • SugarCloud Information
        Find information about SugarCloud service updates and site status. Contact sugarclub@sugarcrm.com to request access
  • More from Sugar
    More from Sugar
    • DevClub
    • PartnerClub
    • Support
    • SugarOutfitters Marketplace
    • sugarcrm.com
  • DevClub
  • PartnerClub
  • Support
  • Marketplace
  • sugarcrm.com
DevClub
DevClub
Dev Tutorials Rector Basic Setup
  • Dev Blog
  • Answers & Best Practices
  • Developer On-boarding
  • Dev Tutorials
  • Developer Events
  • Event Recaps
  • Members
  • Developer Suggestions
  • Sub-Groups
  • More
  • Cancel
  • New
Click here to join this group and curate your SugarClub experience.
  • +On-Boarding Framework
  • +Customization Guides
  • +Modern UI Technical Guide
  • -Automated PHP Compatibility Tool
    • Rector Basic Setup
    • Prepare Rector for MLP/Addon
    • Prepare Rector for Customizations
    • Executing Rector
    • Keeping Compatibility
    • Troubleshooting Rector
    • PHP 7.4 Warnings to PHP8.2 Errors
  • +Customization Best Practices in Sugar
  • How to write code for SugarCloud webinar Q&A
  • HOW TO: enforce ACL on Tags
  • Remove custom fields created via package installation
  • Sugar Developer Tools
  • Tutorial:  How to register custom platforms in Sugar instances via Platform extension
  • Adding a google reCAPTCHA in a Web-to-Lead form
  • Sugar Developer Blog Style Guide

You are currently reviewing an older revision of this page.

  • History View current version

Rector Basic Setup

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

  1. Download a build of SugarCRM. Please use the one that is compatible with your MPL.
  2. Install the build locally or use your own Sugar instance if you have one local
  3. Download the latest rector release and unzip it into the Sugar instance folder. ex: /path/to/sugar/rector-0.15.20
  4. Rector needs phpstan tool to run, for that create a new file in the Sugar instance folder called stan.neon. ex: /path/to/sugar/stan.neon 
  5. parameters:
    	level: 1
    	bootstrapFiles:
    		- include/entryPoint.php
    
  6. 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.
  7. Create /path/to/sugar/.gitignore file to skip the unneeded changes with the following contents:
  8. cache
    vendor
    portal2
    upload
    upgrades
    *.log
    rector.php
    
  9. Commit the initial repository state
  10. git add . && git commit -am 'init'
    
  11. Initialize rector config:
  12. cd /path/to/sugar && rector-0.15.20/bin/rector init
    
  13. 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
        //    ]);
    };