定制 remp/crm-rector 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

remp/crm-rector

Composer 安装命令:

composer require remp/crm-rector

包简介

Rector rules for REMP/Crm

README 文档

README

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
    ]);

    // set with CRM v3 and CRM v4 changes; check README for details
    $rectorConfig->sets([
        CrmSetList::CRM_4,
    ]);

    // run single rule if you don't want to run whole set
    // $rectorConfig->rule(\Crm\Utils\Rector\UpgradeToCrm4\InputParamChangeRector::class);
    // $rectorConfig->rule(\Crm\Utils\Rector\UpgradeToCrm4\RemoveParamsProcessorRector::class);

    // automatically import/remove namespaces after all rules are applied
    $rectorConfig->importNames();
    $rectorConfig->importShortClasses(false);
    $rectorConfig->removeUnusedImports();
};

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 v3 to CRM v4

Set

Use set CrmSetList::CRM_4:

$rectorConfig->sets([\Crm\Utils\Rector\Set\CrmSetList::CRM_4]);

// removes import of Crm\ApiModule\Models\Params\InputParam
$rectorConfig->removeUnusedImports();

// imports new *InputParam classes
$rectorConfig->importNames();

or individual subsets / rules.

Subsets

Replace deprecated BaseWidget and WidgetManager

This set (CrmSetList::CRM_4_LAZY_WIDGET_MANAGER) replaces deprecated classes BaseWidget and WidgetManager with BaseLazyWidget and LazyWidgetManager. They were deprecated since version 2.1.0, commit remp/crm-application-module@43d9c19f37

Replace PaymentsRepository and RecurrentPaymentsRepository constants with enums

This set (CrmSetList::CRM_4_ENUMS) handles renames of few enums where class name didn't contain context:

  • Crm\PaymentsModule\Models\ParsedMailLog\StateEnum renamed to ParsedMailLogStateEnum,
  • Crm\PaymentsModule\Models\RecurrentPayment\StateEnum renamed to RecurrentPaymentStateEnum,
  • Crm\UsersModule\Models\AddressChangeRequest\StatusEnum renamed to AddressChangeRequestStatusEnum.

And replaces all deprecated constants with enums:

  • PaymentsRepository constants replaced by PaymentStatusEnum enums,
  • RecurrentPaymentsRepository constants replaced by RecurrentPaymentStateEnum enums,
  • ParsedMailLogsRepository constants replaced by ParsedMailLogStateEnum enums,
  • AddressChangeRequestsRepository constants replaced by AddressChangeRequestStatusEnum enums.

Rules

Transform Crm\ApiModule\Models\Params\InputParam to specific *InputParam objects

This rule (\Crm\Utils\Rector\UpgradeToCrm4\InputParamChangeRector) changes \Crm\ApiModule\Models\Params\InputParam to specific InputParam object from tomaj/nette-api library.

See what will be changed in getRuleDefinition() method in \Crm\Utils\Rector\UpgradeToCrm4\InputParamChangeRector

Remove calls of deprecated methods from ParamsProcessor

This rule (\Crm\Utils\Rector\UpgradeToCrm4\RemoveParamsProcessorRector) will remove useless calls of ParamsProcessor. Some of these methods were removed (hasError()). And getErrors() or getValues() (loading API parameters from ParamsProcessor) are not needed anymore. API runner handles errors before loading handler and provides validated parameters to handle() method.

WARNING: This Rector rule does crude work. You still need to go through all changes and fix your API handlers (if you worked or need to work with errors).

If you use ApiParamsValidatorInterface, do not run this Rector rule. It doesn't understand this context.

See what will be changed in getRuleDefinition() method in \Crm\Utils\Rector\UpgradeToCrm4\RemoveParamsProcessorRector

Transform Nette annotations to attributes

Set:

$rectorConfig->sets([\Crm\Utils\Rector\Set\CrmSetList::NETTE_ANNOTATIONS_TO_ATTRIBUTES]);

Changes:

    /** @var @inject */
    public Crm\UsersModule\Repositories\UsersRepository $usersRepository;

to:

    #[\Nette\DI\Attributes\Inject]
    public Crm\UsersModule\Repositories\UsersRepository $usersRepository;

Fixes also persistent and crossOrigin.

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,
    ]);

[ARCHIVED] Upgrade CRM v0.38 -> CRM v1.0

ℹ️ We are not maintaining this set anymore. Set & rules were removed. Last release with working rules is https://github.com/remp2020/crm-rector/releases/tag/1.2.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.

remp/crm-rector 适用场景与选型建议

remp/crm-rector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.68k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 remp/crm-rector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 remp/crm-rector 我们能提供哪些服务?
定制开发 / 二次开发

基于 remp/crm-rector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.68k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 6
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-06