From acc
Generates rector.php configs for PHP projects with sets for PHP version upgrades, code quality rules, dead code removal, PHPUnit testing migrations, Symfony/Doctrine framework migrations.
How this skill is triggered — by the user, by Claude, or both
Slash command
/acc:create-rector-configThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Generates optimized Rector configurations for automated PHP refactoring.
Generates optimized Rector configurations for automated PHP refactoring.
rector.php # Main configuration
<?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,
);
<?php
// rector.php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\SetList;
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
])
->withPhpSets(php84: true)
->withSets([
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
SetList::DEAD_CODE,
SetList::EARLY_RETURN,
SetList::PRIVATIZATION,
SetList::TYPE_DECLARATION,
SetList::INSTANCEOF,
])
->withPreparedSets(
deadCode: true,
codeQuality: true,
typeDeclarations: true,
privatization: true,
earlyReturn: true,
strictBooleans: true,
);
<?php
// rector.php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;
return RectorConfig::configure()
->withPaths([
__DIR__ . '/tests',
])
->withPhpSets(php84: true)
->withSets([
PHPUnitSetList::PHPUNIT_100,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
])
->withPreparedSets(
phpunitCodeQuality: true,
);
<?php
// rector.php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Symfony\Set\SymfonySetList;
use Rector\Doctrine\Set\DoctrineSetList;
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhpSets(php84: true)
->withSets([
// Symfony 7.x
SymfonySetList::SYMFONY_70,
SymfonySetList::SYMFONY_CODE_QUALITY,
SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
// Doctrine
DoctrineSetList::DOCTRINE_ORM_30,
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
])
->withSymfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');
<?php
// rector.php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\SetList;
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,
])
// Configure individual rules
->withConfiguredRule(
\Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector::class,
[
// Custom naming rules
]
);
->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
)
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
])
// 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_ORM_30
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES
// PHPUnit
use Rector\PHPUnit\Set\PHPUnitSetList;
PHPUnitSetList::PHPUNIT_100
PHPUnitSetList::PHPUNIT_CODE_QUALITY
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES
->withSkip([
__DIR__ . '/src/Legacy/*',
__DIR__ . '/src/Infrastructure/Migrations/*',
__DIR__ . '/var/*',
__DIR__ . '/vendor/*',
])
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/*',
],
])
# Preview changes without applying
vendor/bin/rector process --dry-run
# Output diff format
vendor/bin/rector process --dry-run --output-format=json
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")
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"
// 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,
) {}
}
// Removes:
// - Unused private methods
// - Unused private properties
// - Unreachable code after return/throw
// - Empty methods that do nothing
// - Unused parameters (configurable)
// 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;
}
Analyze project:
Select sets:
Configure skips:
Generate config:
Provide:
The generator will:
npx claudepluginhub dykyi-roman/awesome-claude-code --plugin accModernizes PHP codebases to PHP 8.1–8.5 with Rector, PHPStan, PHP-CS-Fixer, PHPat, DTOs, enums, readonly, property hooks, and PSR/PER-CS compliance. Includes guarded workflows for Doctrine, Symfony, API Platform, and mutation testing.
Step-by-step PHP version upgrade playbook covering 8.0 through 8.4+ with automated tooling. Guides users through auditing, running Rector, fixing deprecations, and testing.
Modernizes PHP codebases with PHP 8.1-8.5 features, PSR/PER-CS compliance, static analysis via PHPStan/Rector/PHP-CS-Fixer, and type-safety patterns like DTOs, enums, and readonly classes.