ixa-devstuff/php-deprecation-detector

用于检测PHP代码在新版本解释器中已弃用功能问题的分析器。

2.0.29 2022-09-16 03:57 UTC

This package is auto-updated.

Last update: 2024-09-16 08:05:09 UTC


README

PhpDeprecationDetector - 检测PHP代码在新版本解释器中已弃用功能使用的分析器 - 弃用功能检测器。

Latest Stable Version Total Downloads License

PhpDeprecationDetector 检测以下内容

  • 已弃用的 函数、变量、常量和ini指令 的使用。
  • 已弃用 函数功能 的使用。
  • 使用 禁止的名称或技巧(例如,新版本中的保留标识符)。

它实际上可以帮助您找到在迁移到新版本PHP后可能失败的代码。

  1. 安装
  2. 使用方法

安装

Composer

  1. 安装Composer
curl -sS https://getcomposer.org/installer | php
  1. 在全局Composer目录中安装phpdd
./composer.phar global require ixa-devstuff/php-deprecation-detector dev-master
  1. 从任何文件夹运行
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 选项指定所有扩展名。默认情况下,它使用 phpphtmlphp5
  • 如果您需要生成机器可读的分析结果,请使用 --output-json 选项指定存储json的路径,或将 --output-json=- 打印到标准输出。

使用示例

> ./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”)
    • string checker - 可能引起问题的具体问题对象(例如,magic_quotes_runtimepreg_replace() (@preg_replace_e_modifier)
  • ReplaceSuggestion 结构
    • string type - 替换对象类型(例如,“variable”或“ini”)
    • 字符串 问题 - 替换对象(例如 mcrypt_generic_end() 或 each()
    • 字符串 替换建议 - 建议替换为(例如 mcrypt_generic_deinit() 或 foreach()
  • 注意 结构
    • 字符串 类型 - 注意类型(例如 function_usage 或 deprecated_feature
    • 字符串 问题 - 注意对象(例如 preg_replace() (@preg_replace_e_modifier)parse_str() (@parse_str_without_argument)
    • 字符串 注意 - 注意文本(例如 preg_replace 中 "e" 修饰符的使用已弃用: "asdasdsd~ie"在不提供第二个参数的情况下调用 parse_str() 已弃用