Is there a static code analyzer [like Lint] for PH

2018-12-31 19:16发布

Is there a static code analyzer for PHP files? The binary itself can check for syntax errors, but I'm looking for something that does more, like unused variable assignments, arrays that are assigned into without being initialized first, and possibly code style warnings. Open-source programs would be preferred, but we might convince the company to pay for something if it's highly recommended.

标签: php lint
12条回答
闭嘴吧你
2楼-- · 2018-12-31 19:58

There is absolutely new tool for static code analysis called PHP Analyzer.

Among many types of static analysis it also provides basic auto-fixing functionality, see documentation.

UPDATE: PHP-Analyzer is now deprecated project but you still can access it on legacy branch

查看更多
谁念西风独自凉
3楼-- · 2018-12-31 19:59

PHP Mess Detector is awesome and fast.

查看更多
还给你的自由
4楼-- · 2018-12-31 19:59

There is RIPS - A static source code analyser for vulnerabilities in PHP scripts. Sources of RIPS available at SourceForge.

From the RIPS site:

RIPS is a tool written in PHP to find vulnerabilities in PHP applications using static code analysis. By tokenizing and parsing all source code files RIPS is able to transform PHP source code into a program model and to detect sensitive sinks (potentially vulnerable functions) that can be tainted by userinput (influenced by a malicious user) during the program flow. Besides the structured output of found vulnerabilities RIPS also offers an integrated code audit framework for further manual analysis.

查看更多
千与千寻千般痛.
5楼-- · 2018-12-31 20:01

You may want to try compiling with Facebook's hiphop.

It does a static analysis on the entire project, and may be what you're looking for.

https://github.com/facebook/hiphop-php

查看更多
旧时光的记忆
6楼-- · 2018-12-31 20:05

For completeness -- also check phpCallGraph.

查看更多
还给你的自由
7楼-- · 2018-12-31 20:12

Run php in lint-mode from the command line to validate syntax without execution:

php -l FILENAME

Higher-level static analyzers include:

Lower-level analyzers include:

Runtime analyzers, which are more useful for some things due to PHPs dynamic nature, include:

The documentation libraries phpdoc and doxygen perform a kind of code analysis. Doxygen, for example, can be configured to render nice inheritance graphs with graphviz.

Another option is xhprof, which is similar to xdebug, but lighter, making it suitable for production servers. The tool includes a PHP-based interface.

查看更多
登录 后发表回答