php 版本升级后需要对代码进行兼容性检测
来到需要检测代码的目录下 需要提前安装 docker
执行
docker run --rm -v $(pwd):/app vfac/php7compatibility 7.3 . --ignore=vendor --extensions=php,module,inc -d memory_limit=4G |tee -a php7.3.result
–ignore 需要忽略的文件夹
–extensions 可以传入需要检查的文件后缀 如果不传 检查所有
-d memory_limit 传入内存分派大小
可以查看官方文章
https://vfac.fr/projects/php7compatibility
另外这篇文章讲了如何使用 phpcs
但是我没有弄成功
找个文件夹 执行 composer require “squizlabs/php_codesniffer=*“
然后 进入文件夹下的 ./vendor/squizlabs/php_codesniffer/CodeSniffer/Standards
执行
git clone https://github.com/wimg/PHPCompatibility.git
之后
./vendor/bin/phpcs -i
看到这里面并不包含 我们需要的 PHPCompatibility
则添加一下
phpcs --config-set installed_paths ./vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/PHPCompatibility
也有人说这个路径是 ./vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/
但是我试了 ./vendor/bin/phpcs -i 还是不行
The installed coding standards are PSR1, PSR2, PEAR, PHPCS, MySource, Zend, Squiz, PSR1, PSR2, PEAR, PHPCS, MySource, Zend and Squiz
其他的倒是很好用
./vendor/bin/phpcs --standard=PSR2 --runtime-set testVersion 7.1 ~/script/php/for.php
得到
----------------------------------------------------------------------FOUND11 ERRORS AFFECTING 5LINES----------------------------------------------------------------------
14 | ERROR | [x] Expected 1 space after FOR keyword; 0found14 | ERROR | [x] Expected 1space after first semicolon of FOR loop;| | 0found14 | ERROR | [x] Expected 1space after second semicolon of FOR| | loop; 0found14 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
15 | ERROR |[x] Spaces must be used to indent lines; tabs are not| |allowed32 | ERROR | [x] Expected 1 space after FOR keyword; 0found32 | ERROR | [x] Expected 1space after first semicolon of FOR loop;| | 0found32 | ERROR | [x] Expected 1space after second semicolon of FOR| | loop; 0found32 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
33 | ERROR |[x] Spaces must be used to indent lines; tabs are not| |allowed48 | ERROR |[x] A closing tag is not permitted at the end of a PHP| | file
----------------------------------------------------------------------PHPCBF CAN FIX THE11MARKED SNIFF VIOLATIONS AUTOMATICALLY----------------------------------------------------------------------Time: 39ms; Memory: 6Mb