analyse-with-phpstan
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAnalyse PHP code with PHPStan
用PHPStan分析PHP代码
Analyse PHP code using the PHPStan playground API at . This runs PHPStan across PHP versions 7.2–8.5 and returns errors for each version.
https://api.phpstan.org/analyseThe code to analyse:
$ARGUMENTS使用位于的PHPStan playground API分析PHP代码,该API会在PHP 7.2至8.5的所有版本下运行PHPStan并返回每个版本对应的错误。
https://api.phpstan.org/analyse待分析的代码:
$ARGUMENTSStep 1: Prepare the code
步骤1:准备代码
Get the PHP code to analyse. If is a file path, read the file contents. The code must start with .
$ARGUMENTS<?php获取待分析的PHP代码。如果是文件路径,则读取文件内容。代码必须以开头。
$ARGUMENTS<?phpStep 2: Determine settings
步骤2:确定配置
Unless the user specified otherwise, use these defaults:
- level: (strictest)
"10" - strictRules:
false - bleedingEdge:
false - treatPhpDocTypesAsCertain:
true
If the user asked for strict rules or bleeding edge, set those to .
true除非用户另有指定,否则使用以下默认配置:
- level: (最严格)
"10" - strictRules:
false - bleedingEdge:
false - treatPhpDocTypesAsCertain:
true
如果用户要求启用严格规则或前沿特性,则将对应配置设为。
trueStep 3: Call the playground API
步骤3:调用playground API
Submit the code via POST:
bash
curl -s -X POST 'https://api.phpstan.org/analyse' \
-H 'Content-Type: application/json' \
-d '{
"code": "<PHP code, JSON-escaped>",
"level": "<level>",
"strictRules": <true|false>,
"bleedingEdge": <true|false>,
"treatPhpDocTypesAsCertain": <true|false>,
"saveResult": true
}'The code value must be properly JSON-escaped (escape quotes, backslashes, newlines).
通过POST提交代码:
bash
curl -s -X POST 'https://api.phpstan.org/analyse' \
-H 'Content-Type: application/json' \
-d '{
"code": "<PHP code, JSON-escaped>",
"level": "<level>",
"strictRules": <true|false>,
"bleedingEdge": <true|false>,
"treatPhpDocTypesAsCertain": <true|false>,
"saveResult": true
}'代码值必须正确进行JSON转义(转义引号、反斜杠、换行符)。
Step 4: Parse the response
步骤4:解析响应
The response JSON contains:
- — array of objects, one per PHP version, each with:
versionedErrors- — integer encoding: e.g.
phpVersion= PHP 8.4,80400= PHP 7.470400 - — array of error objects with
errors,message,line,identifier(optional),tipignorable
- — UUID for the saved result
id
Convert integers to readable strings: .
phpVersionMath.floor(v / 10000).Math.floor((v % 10000) / 100)响应JSON包含:
- — 对象数组,每个PHP版本对应一个对象,包含:
versionedErrors- — 整数编码:例如
phpVersion= PHP 8.4,80400= PHP 7.470400 - — 错误对象数组,包含
errors、message、line、identifier(可选)、tipignorable
- — 保存结果的UUID
id
将整数转换为易读的字符串: + + 。
phpVersionMath.floor(v / 10000).Math.floor((v % 10000) / 100)Step 5: Present results as markdown
步骤5:将结果以markdown格式呈现
Output the results in this format:
按照以下格式输出结果:
Playground link
Playground链接
https://phpstan.org/r/<id>https://phpstan.org/r/<id>Settings used
所用配置
Level: | Strict rules: yes/no | Bleeding edge: yes/no
<level>级别: | 严格规则: 是/否 | 前沿特性: 是/否
<level>Errors
错误
Group consecutive PHP versions that have identical errors (same messages, lines, and identifiers) into ranges. For example, if PHP 7.2–8.3 all report the same errors, show them as one group.
If all PHP versions report identical errors, show a single group:
All PHP versions (no differences):
| Line | Error | Identifier |
|---|---|---|
| 10 | | |
If errors differ across versions, show separate groups:
PHP 8.0 – 8.5:
| Line | Error | Identifier |
|---|---|---|
| 10 | | |
PHP 7.2 – 7.4:
No errors.
If there are no errors on any PHP version, say: No errors found on any PHP version.
将错误完全相同(相同的消息、行号和标识符)的连续PHP版本合并为范围组。例如,如果PHP 7.2–8.3都报告相同的错误,将它们归为一组。
如果所有PHP版本报告的错误都相同,则显示单个分组:
所有PHP版本(无差异):
| 行号 | 错误 | 标识符 |
|---|---|---|
| 10 | | |
如果不同版本的错误存在差异,则显示单独的分组:
PHP 8.0 – 8.5:
| 行号 | 错误 | 标识符 |
|---|---|---|
| 10 | | |
PHP 7.2 – 7.4:
无错误。
如果所有PHP版本都没有错误,则显示:所有PHP版本均未检测到错误。