phamxuanloc / php-deprecation-detector
用于分析PHP代码,以搜索在新版解释器版本中存在过时功能的问题。
2.0.29
2022-06-16 00:36 UTC
Requires
- php: >=5.4
- ext-json: *
- ext-tokenizer: *
- symfony/console: ^3.4|^4.0|^5.0
Suggests
- ext-json: Adds ability to store report in JSON format
Replaces
- wapmorgan/php-code-fixer: 2.0.29
This package is auto-updated.
Last update: 2024-08-27 13:51:35 UTC
README
PhpDeprecationDetector - PHP代码中搜索在新版解释器版本中使用的过时功能的分析器 - 过时功能检测器。
PhpDeprecationDetector能够检测:
- 过时的函数、变量、常量和ini-directives的使用。
- 过时的函数功能的使用。
- 使用被禁止的名称或技巧(例如,在新版本中的保留标识符)。
它实际上可以帮助你找到在迁移到新版本的PHP之后可能会失败的代码。
安装
Phar文件
- 只需从发布页面下载phar并将其设置为可执行。
chmod +x phpdd-x.x.x.phar
-
a. 本地安装:从当前文件夹使用它
./phpdd-x.x.x.phar -h
b. 全局安装:将其移动到您的
$PATH
中列出的文件夹之一,并从任何文件夹运行sudo mv phpdd-x.x.x.phar /usr/local/bin/phpdd phpdd -h
Composer
安装phpdd的另一种方式是通过composer。
- 安装composer
curl -sS https://getcomposer.org/installer | php
- 在全局composer目录中安装phpdd
./composer.phar global require phamxuanloc/php-deprecation-detector dev-master
- 从任何文件夹运行
phpdd -h
使用方法
控制台扫描器
要扫描您的文件或文件夹,请启动phpdd
并传递文件或目录名称。
Description:
Analyzes PHP code and searches issues with deprecated functionality in newer interpreter versions.
Usage:
scan [options] [--] <files>...
Arguments:
files Which files you want to analyze (separate multiple names with a space)?
Options:
-t, --target[=TARGET] Sets target PHP interpreter version. [default: "8.0"]
-a, --after[=AFTER] Sets initial PHP interpreter version for checks. [default: "5.3"]
-e, --exclude[=EXCLUDE] Sets excluded file or directory names for scanning. If need to pass few names, join it with comma.
-s, --max-size[=MAX-SIZE] Sets max size of php file. If file is larger, it will be skipped. [default: "1mb"]
--file-extensions[=FILE-EXTENSIONS] Sets file extensions to be parsed. [default: "php, php5, phtml"]
--skip-checks[=SKIP-CHECKS] Skip all checks containing any of the given values. Pass a comma-separated list for multiple values.
--output-json[=OUTPUT-JSON] Path to store json-file with analyze results. If '-' passed, json will be printed on stdout.
-h, --help Display help for the given command. When no command is given display help for the scan command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
- 通过提供额外的
--target
选项,您可以指定要执行较少检查的PHP版本。可用目标版本:5.3,5.4,5.5,5.6,7.0,7.1,7.2,7.3,7.4,8.0。较大的版本包括检查所有先前版本的规则。 - 通过提供
--exclude
选项,您可以排除特定的文件夹或文件以进行分析。例如,--exclude vendor
将阻止检查第三方库。 - 通过提供
--skip-checks
选项,您可以排除分析中的特定检查。 - 如果您的文件具有不寻常的扩展名,您可以通过
--file-extensions
选项指定所有扩展名。默认情况下,它使用php
,phtml
和php5
。 - 如果您需要生成机器可读的分析结果,请使用
--output-json
选项指定存储json的路径或使用--output-json=-
将json打印到stdout。
使用示例
> ./bin/phpdd tests/
Max file size set to: 1.000 MiB
Folder /media/wapmorgan/Локальный диск/Документы/PhpDeprecationDetector/tests
- PHP 5.3 (3) - your version is greater or equal
+------------+---------+---------------------------------------------------------------------+
| File:Line | Type | Issue |
+------------+---------+---------------------------------------------------------------------+
| /5.3.php:2 | removed | Function dl() is removed. |
| /5.3.php:3 | removed | Ini define_syslog_variables is removed. |
| /5.3.php:5 | changed | Function usage piet() (@call_with_passing_by_reference) is changed. |
| | | Call with passing by reference is deprecated. Problem is "&$hoho" |
+------------+---------+---------------------------------------------------------------------+
- PHP 5.4 (2) - your version is greater or equal
+------------+---------+-----------------------------------------------+
| File:Line | Type | Issue |
+------------+---------+-----------------------------------------------+
| /5.4.php:2 | removed | Function mcrypt_generic_end() is removed. |
| | | Consider replace with mcrypt_generic_deinit() |
| /5.4.php:3 | removed | Function magic_quotes_runtime() is removed. |
+------------+---------+-----------------------------------------------+
...
...
...
Json报告格式
您还可以将分析结果存储为json格式以进行自动检查。通过传递--output-json=FILENAME
将结果写入FILENAME
文件或使用--output-json=-
将结果输出到stdout。
json格式 - 包含项的字典
- InfoMessage[] info_messages - 分析过程中关于信息的信息列表。
- Issue[] problems - 在您的代码中找到的问题列表。
- ReplaceSuggestion[] replace_suggestions - 基于您的代码的替换建议列表。
- Note[] notes - 关于新函数行为的说明列表。
项描述
- InfoMessage结构
- string type - 消息类型 - info或warning之一
- string message - 消息文本
- Issue结构
- string version - 具有当前问题的解释器版本(例如,7.2)
- string file - 找到问题的文件的相对路径(例如,src/ProblemClass.php)
- string path - 找到问题的文件的绝对路径(例如,/var/www/html/project/src/ProblemClass.php)
- int line - 文件中找到问题的行
- string category - 问题类别 - changed、removed或violation之一
- string type - 具体的问题类型(例如,“constant”或“identifier”)
- 字符串 检查器 - 可能引起问题的具体问题对象(例如
magic_quotes_runtime
或preg_replace() (@preg_replace_e_modifier)
)
- ReplaceSuggestion 结构
- 字符串 类型 - 替换对象类型(例如变量或 ini)
- 字符串 问题 - 替换对象(例如
mcrypt_generic_end()
或each()
) - 字符串 替换 - 建议替换的内容(例如
mcrypt_generic_deinit()
或foreach()
)
- 注意 结构
- 字符串 类型 - 注意的类型(例如函数使用或已弃用功能)
- 字符串 问题 - 注意对象(例如
preg_replace() (@preg_replace_e_modifier)
或parse_str() (@parse_str_without_argument)
) - 字符串 注意 - 注意文本(例如
preg_replace() 中 "e" 修饰符的使用已弃用: "asdasdsd~ie"
或parse_str() 未提供第二个参数的调用已弃用
)