I. use 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 code, read files, and measure the elements it writes. Using these tools can help us have a complete hierarchical understanding of the code library, even when the code library becomes larger and more complex.
Static analysis tools are a key component of the project process. However, only when they are used regularly and submitted in an ideal way can the static analysis tool truly display the bid value. These tools cover all aspects of the Code, from the counting class and the number of calculated lines, to identifying where similar code segments are prompted to be copied and pasted. Then let's take a look at how static analysis tools help us with two key issues in code quality: coding standards and documentation.
1. phploc
Phploc: https://github.com/sebastianbergmann/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 when we run it repeatedly. Phploc provides information about the project topology and dimensions.
For example, to test a standard WordPress version, run the following command:
$ phploc wordpress
2. phpcpd
Phpcpd: https://github.com/sebastianbergmann/phpcpd
PHP phpcpd looks like a tool for finding similar patterns in code. We use it to identify where the code is copied or pasted in the code library. This is a very useful tool in the general build process, but obtaining 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
Phpmd: http://phpmd.org/
The PHP project message detector (phpmd) is a tool that attempts to quantify the "smell of code" called by developers. It uses a series of metrics to find seemingly unbalanced project elements. This tool generates a large amount of output, most of which are good suggestions. The following is a command that requires PHP to check for naming disorder in WordPress:
$ phpmd wordpress/ text naming
Ii. coding standards
Coding standards are a topic that has aroused heated debate among many development teams. Since indentation and space usage do not affect code execution, why should we create formatting rules and strictly abide by them? In fact, it is easier to read when we are used to a certain encoding style and the code is arranged as we expected. However, in the actual development process, it is easy to forget the rules, so you need to check all the code in the tool area.
1. Use the PHP code detector to check encoding standards
PHP code detector: http://pear.php.net/package/PHP_CodeSniffer
First, you need to install this tool on the server. Whether it is on the Development machine or the development server, it depends on the available resources you have.
After installation, you can use the following command to test the Code:
phpcs --standard=PEAR robot.php
2. View information that violates the encoding standard
The PHP code detector has several very important report styles. You can use them to look at the "key" of the code library used, and output these to the screen in the same way as detailed reports, they can also generate other formats.
To generate a summary report, you only need to do this:
phpcs --standard=PEAR --report=summary *
3. View PHP code detector standards
Several coding standards are run by default by the PHP code detector. You can generate or set any of your own standards. If you want to see the available standards, you can run the phpcs with the-I switch.
$ phpcs -i
Iii. Documents and code
Use phpDocumentor to convert comments into 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: The http://git-scm.com/
5. Automatic deployment
PHP: http://www.phing.info/
Phing is a Project Construction System Based on Apache ANT. Phing uses XML-based configuration and is saved in a file named build. xml by default.
Run the command for this project and define a series of tasks belonging to this project. You can also specify which tasks are run by default. You can configure them through Phing.