來到需要檢測代碼的目錄下 需要提前安裝 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
得到
---------------------------------------------------------------------- FOUND 11 ERRORS AFFECTING 5 LINES ---------------------------------------------------------------------- 14 | ERROR | [x] Expected 1 space after FOR keyword; 0 found 14 | ERROR | [x] Expected 1 space after first semicolon of FOR loop; | | 0 found 14 | ERROR | [x] Expected 1 space after second semicolon of FOR | | loop; 0 found 14 | ERROR | [x] Expected 1 space after closing parenthesis; found 0 15 | ERROR | [x] Spaces must be used to indent lines; tabs are not | | allowed 32 | ERROR | [x] Expected 1 space after FOR keyword; 0 found 32 | ERROR | [x] Expected 1 space after first semicolon of FOR loop; | | 0 found 32 | ERROR | [x] Expected 1 space after second semicolon of FOR | | loop; 0 found 32 | ERROR | [x] Expected 1 space after closing parenthesis; found 0 33 | ERROR | [x] Spaces must be used to indent lines; tabs are not | | allowed 48 | ERROR | [x] A closing tag is not permitted at the end of a PHP | | file ---------------------------------------------------------------------- PHPCBF CAN FIX THE 11 MARKED SNIFF VIOLATIONS AUTOMATICALLY ---------------------------------------------------------------------- Time: 39ms; Memory: 6Mb