alexia / php7mar

此包已被弃用,不再维护。未建议替代包。

PHP 7 MAR,或简称“php7mar”,是一个命令行工具,用于生成现有PHP 5代码的报告,帮助开发者快速将其代码移植到PHP 7。

安装次数 63,004

依赖: 0

建议者: 0

安全: 0

星标: 772

关注者: 37

分支: 86

开放问题: 33

类型:项目

v0.2.0-beta 2016-04-26 16:11 UTC

This package is not auto-updated.

Last update: 2020-08-21 20:06:58 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生成的报告非常重要。

它能处理非常糟糕的代码风格吗?

非常糟糕的代码风格将难以解析,但假设代码风格至少有一些结构,它仍然可以被解析。如果代码格式过于糟糕,可以使用一些网站来清理源代码。

用法

首先,下载或克隆此存储库。它不需要放置在包含源代码的文件夹中。

要开始,请在命令行上输入

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"*

--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"。