I. Measurement of quality using static analysis tools
We use static analysis to measure the code without running it. In fact, we use these tools to evaluate code, read files, and measure the features it writes. Using these tools can help us to have a complete hierarchical understanding of the code base, even when the codebase becomes larger and more complex.
Static analysis tools are a key component of the project process, but the static analysis tools really show value only if they are used on a regular basis and each commit is made in an ideal way. These tools cover all aspects of code, from counting classes and counting rows to identifying similar code snippets where you are prompted to use copy and paste. Then let's look at how static analysis tools can help us on two particularly critical issues in code quality: coding standards and documentation.
1, Phploc
Phploc:https://github.com/sebastianbergmann/phploc
The PHP Line of code (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 version of WordPress, we only need to use the following command:
$ phploc WordPress
2, PHPCPD
Phpcpd:https://github.com/sebastianbergmann/phpcpd
The PHP copy-paste (PHPCPD) appears to be a tool that looks for similar patterns in code, and we use it to identify where in the code base the code is copied or pasted. This is a very useful tool in the regular build process, but getting the correct number from the output makes the project different from the project.
Similarly, if we test WordPress, you can use the following command:
$ PHPCPD WordPress
3, PHPMD
phpmd:http://phpmd.org/
The PHP Project message detector (PHPMD) is a tool that tries to quantify the "smell of code" that the so-called development veteran says. It uses a series of indicators to find elements of a project that seem unbalanced. The tool generates a lot of output, most of which are good suggestions, here's a command that asks PHPMD to check for naming clutter in WordPress:
$ PHPMD wordpress/ text naming
Second, the coding standard
The coding standard is a topic that has been hotly debated in many development teams, since indenting and using spaces do not affect the running of the code, why should we create a formatted rule and strictly abide by it? In fact, it becomes easier to read when we are accustomed to a coding style and the code is arranged in the way we want it to be. However, in the actual development process, it is easy to forget the rules, so the tool area needs to check all the code.
1. Check the coding standards using PHP code detectors
PHP code probe: Http://pear.php.net/package/PHP_CodeSniffer
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 available to you.
Once installed, you can test the code using the following command:
Phpcs--standard=pear robot.php
2. See where the coding standards are violated
PHP code detectors have several very important report styles that you can use to look at the "focus" of the codebase you're using, and we'll 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, and you can generate or set any of your own standards. To see what standards are available, you can run the phpcs with the-i switch.
$ phpcs-i
Iii. Documentation and code
Use Phpdocumentor to convert comments to documents.
phpdocumentor:http://www.phpdoc.org/
For example:
Phpdoc-t Docs-o html:smarty:php-d.
Iv. Source code Management
Common source code management tools:
subversion:http://subversion.apache.org/
git:http://git-scm.com/
Five, automatic deployment
phing:http://www.phing.info/
Phing is an Apache ANT-based project building system. Phing uses XML-based configuration, which is saved by default in a file named Build.xml.
We give this project a command and define a series of tasks that belong to this project, and you can also specify which tasks are run by default and can be configured by phing.
http://www.bkjia.com/PHPjc/780763.html www.bkjia.com true http://www.bkjia.com/PHPjc/780763.html techarticle I. Measurement of quality using static analysis tools We measure the code with static analysis without running it. In fact, we use these tools to evaluate the code, read the file, measure what it writes ...