بنقرة واحدة
upgrade-php
// PHP Upgrade Assistant. Use when upgrading PHP version, fixing deprecations for a target PHP version, or scanning for PHP compatibility issues.
// PHP Upgrade Assistant. Use when upgrading PHP version, fixing deprecations for a target PHP version, or scanning for PHP compatibility issues.
Review PHP code using PhpStorm inspections. Use when editing PHP files, reviewing code quality, fixing PHP issues, or when asked about PHP best practices.
Foundational PHP project knowledge for AI agents. Use when working on a PHP project, setting up a PHP development environment, understanding PHP project structure, following PHP coding standards, running PHP tests, using Composer, or when guidance on PHP-specific tools and workflows in PhpStorm is needed.
| name | upgrade-php |
| description | PHP Upgrade Assistant. Use when upgrading PHP version, fixing deprecations for a target PHP version, or scanning for PHP compatibility issues. |
Helps upgrade a PHP project to a target PHP version by scanning for deprecations, reporting issues, applying automated fixes after confirmation, and verifying the result.
Ask the user for the target PHP version if not already stated.
get_php_project_config()
This returns the configured PHP language level, interpreter details (name, path, local/remote), and runtime information (exact version, loaded extensions, debuggers). Use it to determine the current PHP version the project is targeting.
get_composer_dependencies()
If no packages are returned, warn: "No composer.json found. Proceeding with code-only scan."
get_file_text_by_path(pathInProject: "composer.json")
Look for "require": { "php": "..." } and config.platform.php.
Report to the user: Current: PHP >=X.Y → Target: PHP Z.W
Scan the project to build a complete issue inventory. Do not fix anything yet.
find_files_by_glob(globPattern: "**/*.php")
Exclude vendor/ from scanning. For large projects (>200 files), scan src/, app/ first, then tests/ separately.
get_inspections(
filePath: "<relative-path>",
minSeverity: "WEAK_WARNING"
)
Common deprecation-related problems will have descriptions mentioning:
${})implode() argument orderFor patterns inspections may miss, use structural search:
# Dynamic properties (deprecated in PHP 8.2)
search_structural(
pattern: "$obj$->$prop$ = $val$",
fileType: "PHP",
maxResults: 50
)
Pattern syntax: Use $name$ for template variables (e.g., $a$->$b$() matches any method
call on any object). Use $a${2,5} for count constraints, $a$+ for one-or-more, $a$* for
zero-or-more.
Categorize all discovered issues:
| Priority | Category | Count | Auto-fixable |
|---|---|---|---|
| P0 | Errors (breaking in target version) | N | Y/N |
| P1 | Deprecations (removed in target) | N | Y/N |
| P2 | Deprecations (warned in target) | N | Y/N |
Present this table to the user. Wait for explicit confirmation before proceeding to fixes.
Apply fixes only after user confirmation. Process in priority order: P0 → P1 → P2.
For each problem where quickFixes is non-empty:
apply_quick_fix(
filePath: "<path>",
line: <line>,
column: <column>,
quickFixName: "<quickFixes[0].name>"
)
Strategy:
get_inspections(filePath: "<path>", minSeverity: "WEAK_WARNING")
When quickFixes is empty:
description — it usually names the replacement.get_file_text_by_path.replace_text_in_file.Common manual fix patterns:
| Deprecation | Before | After |
|---|---|---|
| Implicitly nullable params (8.4) | function f(Type $p = null) | function f(?Type $p = null) |
${} interpolation (8.2) | "Hello ${name}" | "Hello {$name}" |
| Partially-supported callables (8.2) | $c = "self::method" | $c = self::method(...) |
If no replacement is documented, add a // TODO: PHP <target> - <description> comment
and include in the "Remaining" report.
After code fixes, update the PHP version constraint:
replace_text_in_file(
pathInProject: "composer.json",
oldText: "\"php\": \">=8.1\"",
newText: "\"php\": \">=8.4\""
)
Do NOT run composer update automatically. Advise the user to run it manually.
Re-run get_inspections on all modified files with minSeverity: "WEAK_WARNING".
Confirm zero remaining deprecation issues.
Check for available test configurations:
get_run_configurations()
Suggest the user run their test suite. Do not execute tests automatically unless the user explicitly asks.
PHP Upgrade Summary: X.Y → Z.W
────────────────────────────────
Files scanned: N
Issues found: M
Auto-fixed: A
Manually fixed: B
Remaining: C (needs manual review)
composer.json: Updated / Not updated
Next steps:
1. Run `composer update` to validate dependency compatibility
2. Run your test suite
3. Review files listed under "Remaining"
| Case | Handling |
|---|---|
| No quick fix available | Apply manual fix or add TODO comment |
| Breaking changes (P0) | Fix these first — code will fail at runtime |
| Inspection timeout | Re-run with longer timeout or narrow to subdirectory |
| Large project (>500 files) | Scan in batches of 50; offer to scope to specific directories |
| Multiple composer.json | Ask user which sub-project to upgrade |