Using static analysis tools to measure quality We use static analysis to measure the code without running it. In fact, we use these tools to evaluate the code, read the file, and measure the elements it writes. Using these tools can help us to have a complete hierarchical understanding of the code base, even when the code base becomes larger and more complex. Static analysis tools are a key part of the project process, but static analysis tools really show value only if they are used regularly and in an ideal manner for each submission. These tools cover all aspects of the code, from counting classes and counting rows, to identifying similar snippets of code where hints are used to copy and paste. Then let's look at how static analysis tools help us with two particularly critical issues in code quality: coding standards and documentation. 1, phploc PHP code line (PHPLOC) may not be a very interesting static analysis tool, but it does give us some interesting information, especially over time as we run it over and over again. Phploc provides information about the project topology and dimensions. For example, to test a standard WordPress version, we only need to use the following command: $ phploc WordPress 2, PHPCPD The PHP Replicator (PHPCPD) appears to be a tool for finding similar patterns in code that we use to identify where the code is copied or pasted in the code base. This is a very useful tool in the general build process, but getting the correct number from the output will make the project different from the project. Similarly, if we test WordPress, we can use the following command: $ phpcpd WordPress 3, PHPMD PHP Project message detector (PHPMD) is an attempt to Quantify the so-called "code smell" tool that the development veteran calls it. It uses a range of metrics to look for seemingly unbalanced project elements. The tool generates a lot of output, most of which are good suggestions, below is a request to PHPMD in WordPress check naming Chaos command: $ PHPMD wordpress/ text naming II. Coding standards Coding standards are a hotly debated topic in many development teams, and since indenting and using spaces do not affect the operation of the code, why should we create the formatting rules and strictly adhere to them? In fact, when we've gotten used to some coding style, andAnd the code will be easier to read when it is arranged in the way we expect it to. However, in the actual development process, it is easy to forget the rules, so the tool area to check all the code. 1, using PHP code detectors to check coding standards First, you need to install the tool on the server. Whether it's on a development machine or a development server, it all depends on the resources you have available. After the installation, you can use the following command to test the code: phpcs--standard=pear robot.php 2, to view the violation of coding standards in the local The PHP code probes have several very important report styles that you can use to look at the "focus" of the code base you are using, and we will output these in the same way as detailed reports to the screen, and they can also generate other formats. To generate a summary report, just do this: phpcs--standard=pear--report=summary * 3, view PHP code detector standard There are several coding standards that PHP code detectors run by default, You can generate or set any of your own standards. If you want to see what standards are available, you can run a phpcs with the-i switch. $ phpcs-i III, documentation and code use Phpdocumentor to convert annotations to documents. For example: PHPDOC-T docs-o html:smarty:php-d. Iv. source code Control Common source control tools: V, automatic deployment Phing is a project building system based on Apache ANT. Phing uses an xml-based configuration, which is saved by default in a file named Build.xml. We give this project a command, define a series of tasks that belong to this project, and can specify which tasks are run by default and can be configured by phing.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.