create-rector-config

为 PHP 项目生成 Rector 配置,创建包含 PHP 升级规则集、代码质量规则、无用代码移除以及框架特定迁移的 rector.php 文件。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "create-rector-config":https://skillpi.com/zh/skills/deepskill-04487402bf65c4ed25de9a3567482318410d65797a4f0ccd6a21e4d7292c962f。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

为 PHP 项目生成 Rector 配置,创建包含 PHP 升级规则集、代码质量规则、无用代码移除以及框架特定迁移的 rector.php 文件。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
输入和输出
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: create-rector-config
description: Generates Rector configurations for PHP projects. Creates rector.php with PHP upgrade sets, code quality rules, dead code removal, and framework-specific migrations.

Rector Configuration Generator

Generates optimized Rector configurations for automated PHP refactoring.

Targets Rector 2.x (rector/rector: ^2.0) — always the RectorConfig::configure() builder, never the legacy return static function (RectorConfig $rectorConfig): void {} closure with ->import()/->sets().

Generated Files

rector.php                # Main configuration

Configuration by Use Case

PHP Version Upgrade

<?php
// rector.php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/src',
        __DIR__ . '/tests',
    ])
    ->withSkip([
        __DIR__ . '/src/Infrastructure/Legacy',
        __DIR__ . '/src/Infrastructure/Migrations',
    ])
    // PHP 8.4 upgrade
    ->withPhpSets(php84: true)
    // Prepared sets
    ->withPreparedSets(
        deadCode: true,
        codeQuality: true,
        typeDeclarations: true,
    );

Code Quality Focus

<?php
// rector.php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/src',
    ])
    ->withPhpSets(php84: true)
    ->withPreparedSets(
        deadCode: true,
        codeQuality: true,
        codingStyle: true,
        typeDeclarations: true,
        privatization: true,
        naming: true,
        instanceOf: true,
        earlyReturn: true,
        strictBooleans: true,
    );

PHPUnit Migration

<?php
// rector.php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/tests',
    ])
    ->withPhpSets(php84: true)
    // Picks the PHPUnit version sets matching composer.json (PHPUnit 10/11/12)
    ->withComposerBased(phpunit: true)
    ->withAttributesSets(phpunit: true)
    ->withPreparedSets(
        phpunitCodeQuality: true,
    );

Symfony Migration

<?php
// rector.php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/src',
        __DIR__ . '/tests',
    ])
    ->withPhpSets(php84: true)
    // Picks Symfony/Doctrine version sets matching composer.json
    ->withComposerBased(symfony: true, doctrine: true)
    ->withAttributesSets(symfony: true, doctrine: true)
    ->withPreparedSets(
        symfonyCodeQuality: true,
        doctrineCodeQuality: true,
    )
    ->withSymfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');

DDD Project Configuration

<?php
// rector.php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/src/Domain',
        __DIR__ . '/src/Application',
        __DIR__ . '/src/Infrastructure',
        __DIR__ . '/src/Api',
    ])
    ->withSkip([
        __DIR__ . '/src/Infrastructure/Migrations',
        __DIR__ . '/src/Infrastructure/Legacy',

        // Skip certain rules for specific paths
        RemoveUnusedPrivateMethodRector::class => [
            __DIR__ . '/src/Domain/*/Event/*',  // Event handlers may seem unused
        ],
    ])
    ->withPhpSets(php84: true)
    ->withPreparedSets(
        deadCode: true,
        codeQuality: true,
        typeDeclarations: true,
        privatization: true,
        earlyReturn: true,
    )
    // Strict for Domain layer
    ->withRules([
        ReturnTypeFromStrictNativeCallRector::class,
        ReturnTypeFromStrictScalarReturnExprRector::class,
    ]);

Available Set Lists

PHP Version Sets

->withPhpSets(
    php53: true,  // PHP 5.3 features
    php54: true,  // PHP 5.4 features
    php55: true,  // ...
    php56: true,
    php70: true,
    php71: true,
    php72: true,
    php73: true,
    php74: true,
    php80: true,
    php81: true,
    php82: true,
    php83: true,
    php84: true,  // Latest
)

Quality Sets

use Rector\Set\ValueObject\SetList;

->withSets([
    SetList::CODE_QUALITY,          // General code quality
    SetList::CODING_STYLE,          // Coding style improvements
    SetList::DEAD_CODE,             // Remove dead code
    SetList::EARLY_RETURN,          // Early return patterns
    SetList::PRIVATIZATION,         // Privatize where possible
    SetList::TYPE_DECLARATION,      // Add type declarations
    SetList::INSTANCEOF,            // Instanceof improvements
    SetList::STRICT_BOOLEANS,       // Strict boolean comparisons
])

Framework Sets

// Symfony
use Rector\Symfony\Set\SymfonySetList;
SymfonySetList::SYMFONY_60
SymfonySetList::SYMFONY_70
SymfonySetList::SYMFONY_CODE_QUALITY
SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES

// Doctrine
use Rector\Doctrine\Set\DoctrineSetList;
DoctrineSetList::DOCTRINE_ORM_29
DoctrineSetList::DOCTRINE_CODE_QUALITY
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES

// PHPUnit
use Rector\PHPUnit\Set\PHPUnitSetList;
PHPUnitSetList::PHPUNIT_100
PHPUnitSetList::PHPUNIT_CODE_QUALITY
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES

Skip Configuration

Skip Paths

->withSkip([
    __DIR__ . '/src/Legacy/*',
    __DIR__ . '/src/Infrastructure/Migrations/*',
    __DIR__ . '/var/*',
    __DIR__ . '/vendor/*',
])

Skip Rules

use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;

->withSkip([
    // Skip globally
    RemoveUnusedPrivateMethodRector::class,

    // Skip for specific files
    FinalizeClassesWithoutChildrenRector::class => [
        __DIR__ . '/src/Domain/*/Entity/*',
    ],
])

CI Integration

Dry Run (Preview)

# Preview changes without applying
vendor/bin/rector process --dry-run

# Output diff format
vendor/bin/rector process --dry-run --output-format=json

GitHub Actions

rector:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v4
    - uses: shivammathur/setup-php@v2
      with:
        php-version: '8.4'
    - run: composer install
    - name: Check Rector
      run: vendor/bin/rector process --dry-run --ansi

    # Optional: Auto-fix in PR
    - name: Apply Rector
      if: github.event_name == 'pull_request'
      run: |
        vendor/bin/rector process
        git diff --quiet || (git add -A && git commit -m "Apply Rector fixes")

GitLab CI

rector:
  script:
    - vendor/bin/rector process --dry-run
  allow_failure: true

rector:fix:
  script:
    - vendor/bin/rector process
    - git diff --quiet || exit 1
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"

Common Transformations

PHP 8.4 Features

// Before: Null coalescing
$value = isset($array['key']) ? $array['key'] : 'default';

// After: Null coalescing operator
$value = $array['key'] ?? 'default';

// Before: Constructor property promotion
class User {
    private string $name;

    public function __construct(string $name) {
        $this->name = $name;
    }
}

// After: Property promotion
class User {
    public function __construct(
        private string $name,
    ) {}
}

Dead Code Removal

// Removes:
// - Unused private methods
// - Unused private properties
// - Unreachable code after return/throw
// - Empty methods that do nothing
// - Unused parameters (configurable)

Type Declarations

// Adds return types from:
// - Strict native calls (strlen, count, etc.)
// - Scalar return expressions
// - Property types from constructor

// Before
public function getName() {
    return $this->name;
}

// After
public function getName(): string {
    return $this->name;
}

Generation Instructions

  1. Analyze project:

    • Check current PHP version
    • Check target PHP version
    • Identify frameworks (Symfony, Laravel)
    • Check for PHPUnit
  2. Select sets:

    • PHP version upgrade sets
    • Framework migration sets
    • Code quality sets
  3. Configure skips:

    • Legacy directories
    • Generated code
    • Migrations
  4. Generate config:

    • Create rector.php
    • Add appropriate sets
    • Configure skips

Usage

Provide:

  • Current PHP version
  • Target PHP version
  • Frameworks used
  • Directories to process
  • Directories to skip

The generator will:

  1. Create rector.php configuration
  2. Include appropriate version sets
  3. Include framework sets
  4. Configure quality improvements
  5. Set up proper skips

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值90/100

亮点

  • 直接解决 PHP 项目中自动化重构配置生成的核心痛点
  • 提供多种预设场景(PHP版本升级、代码质量、框架迁移等),显著提升开发效率
  • 覆盖主流框架(Symfony、Doctrine、PHPUnit)和常见项目结构
触发精准90/100

亮点

  • 触发词精准完整,覆盖多种变体,边界清晰
  • description 明确描述了 Skill 的核心功能和使用场景
结构规范90/100

亮点

  • Phase/步骤清晰,有出口条件,含端到端示例
  • frontmatter完整,单文件≤500行
  • 文档结构清晰,包含多个使用场景和配置示例
执行可靠90/100

亮点

  • 工具来源明确,参数正确,覆盖主要异常
  • 提供了详细的配置示例和 CI 集成方案
  • 包含 skip 配置和规则定制,确保执行可靠性
证据可验 (前四项均值)90/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。