chrishalbert / php7mar
PHP7Mar带有-x '@exclude'选项,用于忽略在PHP 7中已验证可行的细微差别。"php7mar"是一个命令行工具,用于生成现有PHP 5代码的报告,以帮助开发人员快速将其代码迁移到PHP 7。
Requires
- php: >=5.4.0
This package is auto-updated.
Last update: 2024-09-17 10:16:56 UTC
README
PHP 7迁移助手报告(MAR)是什么?
PHP 7 MAR,或简称"php7mar",是一个命令行工具,用于生成现有PHP 5代码的报告,以帮助开发人员快速将其代码迁移到PHP 7。它可以针对单个文件或整个项目文件夹运行。报告包含行号、问题说明以及带有文档链接的修复建议。
php7mar会自动修复我的代码吗?
不会,php7mar实现了一个完整的词法分析器来确定代码更改,但不能确定代码的意图。它使用词法分析、字符串匹配和正则表达式来查找可能导致将代码迁移到PHP 7时出现问题的语法更改。此外,它还会检测注释中的代码片段,并将它们报告出来,因为它无法将其区分为主释代码。
PHP 7有哪些变化?(阅读此内容!)
如果您目前不了解迁移到PHP 7将发生什么变化,请阅读php-src当前主分支中的UPGRADING文件。理解这些更改对于阅读php7mar生成的报告非常重要。
它能处理非常差的代码风格吗?
非常差的代码风格可能无法很好地解析,但假设代码风格至少有一些结构,它仍然可以解析。如果代码格式过于糟糕,有多个网站可以帮助清理源代码。
- http://www.phpformatter.com/(不支持PHP 5.4 []数组语法。)
- http://phpbeautifier.com/
- http://phpcodecleaner.com/
使用方法
首先,开始下载或克隆此存储库。它不需要放置在包含源代码的文件夹中。
要开始,请在命令行中键入
php mar.php
这将显示可用的参数和开关。
典型用法如下
php mar.php -f="/path/to/file/example.php"
或者
php mar.php -f="/path/to/folder/example/"
这将针对示例文件或文件夹运行,并将生成的报告保存到php7mar文件夹内的reports文件夹中。在引用要运行的文件或文件夹时,建议使用完全限定路径。支持相对路径,但将相对于php7mar文件夹的位置。
试一试,使用包含的testcases.php
生成报告
php mar.php -f="testcases.php"
可用选项
-f
Path to the file or folder to run against.
The location of the file or folder to use for generating the report. A fully qualified path is recommended. Relative paths will be based off the php7mar folder.
*Example: -f="/path/to/folder"*
-r
Path to the folder to save the report.
The location to save the final report. By default this saves into the reports/ folder inside the php7mar folder. A fully qualified path is recommended. Relative paths will be based off the php7mar folder.
*Example: -r="/path/to/folder"*
-t
Types of tests to run.
By default all tests will run. This option allows tests to be selected using a comma delimited list. Allowable values: critical, nuance, and syntax.
*Example: -t="syntax,nuance"*
-x
List of file extension(s) to process.
By default *.php files are processed.
*Example: -x="php,inc"*
-e
Exclusion tags that you can add above a line that is being flagged. Most useful for nuances which will remain in subsequent reports.
*Example: -e="@ignoreNextLine"*
Code:
// @ignoreNextLine
foreach ($array as &$byRef) {
--php
File path to the PHP binary to use for syntax checking.
If this option is not used syntax checking will use the default PHP installtion to test syntax.
*Example: --php="/path/to/php/binary/php"*
测试类型
关键
关键测试查找会导致代码损坏、编译错误或以其他方式创建不符合预期行为的代码的问题。
细微差别
细微差别测试查找可能会引起不可察觉代码行为的错误。这些测试可能会报告许多错误,因为它们无法确定正在检查的代码的意图。
语法
基于基本命令行的语法检查器,用于检查所有文件的标准语法问题。这在执行大量查找和替换操作后进行双重检查很有用。请注意,语法检查会显著增加处理时间,特别是对于大型代码库。要运行而不进行语法检查,请使用-t选项并省略语法;-t="critical,nuance"。