php-modernization
npx machina-cli add skill netresearch/php-modernization-skill/php-modernization --openclawPHP Modernization Skill
Modernize PHP applications to PHP 8.x with type safety, PSR compliance, and static analysis.
Expertise Areas
- PHP 8.x: Constructor promotion, readonly, enums, match, attributes, union types
- PSR/PER Compliance: Active PHP-FIG standards
- Static Analysis: PHPStan (level 9+), PHPat, Rector, PHP-CS-Fixer
- Type Safety: DTOs/VOs over arrays, generics via PHPDoc
Using Reference Documentation
PHP Version Features
When implementing PHP 8.0-8.5 features (constructor promotion, readonly properties, enums, match expressions, attributes), consult references/php8-features.md.
Standards Compliance
When ensuring PSR/PER compliance or configuring PHP-CS-Fixer with @PER-CS, consult references/psr-per-compliance.md for active PHP-FIG standards.
When configuring PHPStan levels or understanding level requirements, consult references/phpstan-compliance.md for level overview and production configuration.
Static Analysis Tools
When setting up PHPStan, PHPat, Rector, or PHP-CS-Fixer, consult references/static-analysis-tools.md for configuration examples and integration patterns.
Type Safety
When implementing type-safe code or migrating from arrays to DTOs, consult references/type-safety.md for type system strategies and best practices.
When creating request DTOs or handling safe integer conversion, consult references/request-dtos.md for DTO patterns and validation approaches.
Architecture Patterns
When implementing adapter registry patterns for multiple external services, consult references/adapter-registry-pattern.md for dynamic adapter instantiation from database configuration.
When using Symfony DI, events, or modern framework patterns, consult references/symfony-patterns.md for architecture best practices.
Migration Planning
When planning PHP version upgrades or modernization projects, consult references/migration-strategies.md for assessment phases, compatibility checks, and migration workflows.
Running Scripts
Project Verification
To verify a PHP project meets modernization requirements:
scripts/verify-php-project.sh /path/to/project
This script checks:
- PHPStan level compliance
- PHP-CS-Fixer configuration
- Type declaration coverage
- DTO usage patterns
Required Tools
When setting up a modernized PHP project, ensure these tools are configured:
| Tool | Requirement |
|---|---|
| PHPStan | Level 9 minimum, level 10 recommended |
| PHPat | Required for defined architectures |
| Rector | Required for automated modernization |
| PHP-CS-Fixer | Required with @PER-CS ruleset |
Core Rules
- DTOs required over arrays for structured data
- Backed enums required for fixed value sets (not constants)
- PSR interfaces for type-hinting dependencies (PSR-3, PSR-6, PSR-7, PSR-11, PSR-14, PSR-18)
See references/core-rules.md for code examples and scoring criteria.
Migration Checklist
-
declare(strict_types=1)in all files - PER Coding Style via PHP-CS-Fixer (
@PER-CS) - PHPStan level 9+ (level 10 for new projects)
- PHPat architecture tests
- Return types and parameter types on all methods
- DTOs for data transfer, no array params/returns
- Backed enums for all status/type values
- Type-hint against PSR interfaces
Contributing: https://github.com/netresearch/php-modernization-skill
Source
git clone https://github.com/netresearch/php-modernization-skill/blob/main/skills/php-modernization/SKILL.mdView on GitHub Overview
PHP Modernization helps upgrade applications to PHP 8.x with type safety and static analysis. It emphasizes DTOs over arrays, backed enums, constructor promotion, and readonly properties, guided by PHPStan, Rector, PHPat, and PHP-CS-Fixer to ensure PSR compliance.
How This Skill Works
Identify target PHP features and tooling. Configure PHPStan, Rector, PHPat, and PHP-CS-Fixer per reference materials, then migrate code to DTOs, enums, and typed signatures. Run the analysis and automated fixes iteratively to reach core rules and compliance.
When to Use It
- Upgrading a legacy PHP application to PHP 8.1+
- Enforcing type safety by replacing arrays with DTOs/VOs
- Setting up static analysis and automated modernization with PHPStan, Rector, and PHPat
- Configuring PHP-CS-Fixer with PER rules for standards compliance
- Modernizing code with PHP 8 features such as enums, constructor promotion, and readonly properties
Quick Start
- Step 1: Assess project readiness for PHP 8.x features and identify DTOs, enums, and readonly properties to introduce
- Step 2: Configure PHPStan (level 9+), PHPat, Rector, and PHP-CS-Fixer with PER rules
- Step 3: Run the modernization loop: convert arrays to DTOs, add type hints, enable constructor promotion and readonly properties, then run static analysis and fixes
Best Practices
- Use DTOs over arrays for all data transfer
- Adopt backed enums for fixed value sets
- Declare strict_types=1 in all files
- Run PHPStan at level 9+ and maintain PHPat tests
- Apply Rector migrations and PHP-CS-Fixer PER rules to maintain consistency
Example Use Cases
- Refactor API layer to return DTOs instead of associative arrays
- Replace status values with backed enums across services
- Introduce readonly value objects for domain entities
- Migrate to constructor promoted properties and union types where applicable
- Automate modernization with Rector scripts and PER-CS configured fixes