Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何仅对分支中更改的文件进行lint或静态分析?_Php_Git_Jenkins_Lint_Phplint - Fatal编程技术网

Php 如何仅对分支中更改的文件进行lint或静态分析?

Php 如何仅对分支中更改的文件进行lint或静态分析?,php,git,jenkins,lint,phplint,Php,Git,Jenkins,Lint,Phplint,我正在使用Jenkins并对Pull请求执行PHPMD、PHPCS和PHPLint检查。我们拥有的基本上是每个特性的一个独立分支,如果通过检查和测试,它应该再次合并到主分支中 我们正在使用以下命令检查项目中的所有php文件: echo "php syntax checks are started" find ./ -type f -name \*.php -exec php -l '{}' \; | grep -v "No syntax errors detected" && e

我正在使用Jenkins并对Pull请求执行PHPMD、PHPCS和PHPLint检查。我们拥有的基本上是每个特性的一个独立分支,如果通过检查和测试,它应该再次合并到主分支中

我们正在使用以下命令检查项目中的所有php文件:

echo "php syntax checks are started"
find ./ -type f -name \*.php -exec php -l '{}' \; | grep -v "No syntax errors detected" && echo "PHP Syntax error(s) detected" && exit 1;
对所有php文件使用“php-l”大约需要几分钟


我想知道是否有一种方法可以加快速度,并提出了一个解决方案。请检查我下面的答案。

考虑到只有很少的php文件会更改,这只需要几秒钟

echo "php syntax checks for only changed files"
( ( (git diff --name-only origin/master $GIT_COMMIT ) | grep .php$ ) | xargs -n1 echo php -l | bash ) | grep -v "No syntax errors detected" && echo "PHP Syntax error(s) detected" && exit 1;
如果你在Jenkins中使用git插件,你可以保留$git_COMMIT,否则用COMMIT number或branch name更改它

这也可以用于css和js lint。更改“php-l”部分取决于您需要什么