Coder Social home page Coder Social logo

crm-rector's Introduction

CRM - Rector rules

This repository contains Rector rules for upgrade of custom modules used with REMP CRM.

How to use

1. Install package

composer require --dev remp/crm-rector

Note: Composer will ask if you trust plugin rector/extension-installer. This plugin installs CRM rules into Rector package.

2. Create rector.php:

Run command:

vendor/bin/rector init

3. Update rector.php

Fill custom paths & options & sets/rules you want to run.

E.g. to update to CRM 1.0 it could look like this:

<?php

declare(strict_types=1);

use Crm\Utils\Rector\Set\CrmSetList;
use Rector\Config\RectorConfig;
use Rector\Core\Configuration\Option;

return static function (RectorConfig $rectorConfig): void {
    $parameters = $rectorConfig->parameters();

    // paths to refactor
    $rectorConfig->paths([
        __DIR__ . '/app/custom-modules', // path to custom modules
         __DIR__ . '/composer.json', // root composer -> updates REMP CRM packages automatically
    ]);

    // optional settings to automatically import namespaces in changed files
    $rectorConfig->importNames();
    $rectorConfig->disableImportShortClasses();

    // set with CRM 1.0 changes; check README for list of sets
    $rectorConfig->sets([
        CrmSetList::CRM_1_0,
    ]);

    // set service if you want to run individual rule; check README for list of rules
    // $services = $rectorConfig->services();
    // $services->set(\Crm\Utils\Rector\UpgradeToCrm1\ApiHandlerJsonResponseRector::class);
};

Sets and rules are listed below.

4. Run Rector:

vendor/bin/rector process --dry-run

After you reviewed planned changes, run it without --dry-run:

vendor/bin/rector process

Use vendor/bin/rector --help for help. Notable flags are -vvv for verbose messages, --clear-cache and --xdebug if you need to debug rector rules.

Sets & rules

Upgrade CRM v0.38 -> CRM v1.0

Check also the CRM 1.0 migration guide.

Sets

  • Set: Crm\Utils\Rector\Set\CrmSetList::CRM_1_0 contains CRM changes and Nette rules (3.0, 3.1).
  • Set: Crm\Utils\Rector\Set\CrmSetList::CRM_1_0_WITHOUT_NETTE contains only CRM changes.
    • You can call Nette sets from your rector.php later.
  • Set: Crm\Utils\Rector\Set\CrmSetList::NETTE_ANNOTATIONS_TO_ATTRIBUTES contains transformation of PHPdoc-based annotations to PHP 8.0 attributes (available since Nette 3.0+).

Individual rules

Note: Both these rules are part of sets CRM_1_0 and CRM_1_0_WITHOUT_NETTE. These are created as individual rules because Rector's general rules were not sufficient. We recommend running whole set.

Transform to lazy event listeners

Individual rules

Upgrade CRM v2.* -> CRM v3.0

  • Set: Crm\Utils\Rector\Set\CrmSetList::CRM_3_0_PSR4 - contains namespace renames after class names / namespaces were changed to follow PSR4 standard.

    Usage:

    $rectorConfig->sets([
        CrmSetList::CRM_3_0_PSR4,
    ]);

crm-rector's People

Contributors

markoph avatar rootpd avatar miroc avatar

Watchers

Tomas Majer avatar  avatar James Cloos avatar Martin Strycek avatar  avatar Adam Žoldák avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.