Today, I chatted with two-and-61-year-younger sister paper about code specifications, I also probably said some need to pay attention to the point, but feel not careful enough, here to share the recently began to use the tool, of course, code specifications but has been very high on their own oh, haha, good not long-winded, the following content is copied from the Internet , just promised to write an article, but just found that this article is still very good to have no difficulty (programmers are very lazy), Source: http://blog.csdn.net/xinhaozheng/article/details/3324796
know Php_codesniffer
Php_codesniffer is a package written by PHP5 in Pear that examines the sniffing of PHP code against a set of predefined coding standards, a necessary development tool to ensure that your code is concise and consistent, and even helps programmers reduce semantic errors.
Install Php_codesniffer
If you have PHP and pear installed on your Web server, you can install Php_codesniffer directly by running the following commands.
$ pear Install Php_codesniffer
After installation, you can typing command phpcs at the command line to invoke Php_codesniffer check code, by default, Php_codesniffer is using Pear's
Coding standard; You can now try it to check that your code meets the coding criteria, such as:
$ phpcs/path/to/code/yourfile.php
If you want to check a directory, you should use the following command:
$ phpcs/path/to/code
How to use Php_codesniffer
The main program using Php_codesniffer is Phpcs, and its specific use can be obtained by running the following command at the command line to obtain the Phpcs parameters and
The appropriate usage information.
$ phpcs-h
Usephp_codesniffer Check file or file directory
The easiest way to use Php_codesniffer is to pass a path directly to Phpcs. If the path points to a file directory, then php_codesniffer checks the file directory and also has all the files in the directory. If you do not want to check all subdirectories, you can add the-l (locally) parameter so that it checks only the files in the current directory. $ phpcs/path/to/code/myfile.inc
$ phpcs/path/to/code/my_dir You can also specify multiple files or directories for Php_codesniffer inspection.
$ phpcs/path/to/code/myfile.inc/path/to/code/my_dirControl the inspection results of php_codesniffer output
After checking the file, Php_codesniffer will give you an error report listing the error and warning messages that violate the coding standards in all files.
If you do not want to include a warning message (WARNING) in the output's check results, you can add the-n parameter to the phpcs. By default, Php_codesniffer prints out a list of all errors and warnings after the file is checked, usually very long, especially when checking for more files, the list is long and fast, and you don't see anything at all. At this point you may only need to know how many error and warning messages each file has, and you can use the--report=summary parameter. $ phpcs--report=summary/path/to/code
In addition, Php_codesniffer can also output the inspection results in a xml,csv and similar format to the Checkstyle output, which facilitates you in your own scripts to analyze the progress of the inspection results or to provide support to checkstyle application processing.
$ phpcs--report=checkstyle/path/to/code
$ phpcs--report=csv/path/to/code
$ phpcs--report=checkstyle/path/to/code
Note: When you output the check results in CSV format, the first line of the output indicates the order in which the result information is checked (that is, what column is on the information).
In addition, Php_codesniffer does not output any information during processing until the end of the output check results. When dealing with more files, it may take a long time to wait, and if you want to know what's going on in the process, you can take the php_codesniffer with the-v argument, so php_ Codesniffer the name of the file currently being processed, the number of rows and identifiers included in the process.
$ phpcs/path/to/code/codesniffer-v
setting the related configuration options for Php_codesniffer
Php_codesniffere has some configuration options available, and some coding standards can only be used when configuration options are set. To set a hp_codesniffer configuration option, you can use:
$ phpcs--config-set <option> <value>
You can use the following command to remove any configuration options so that it reverts to its original value.
$ phpcs--config-delete <option>
Use the following to view the current settings of the configuration options
$ phpcs--config-show
The following is a list of Php_codesniffer configuration options and how they are set up:
Default_standard the default encoding standard
Report_format default Error Reporting format
Show_warnings whether the warning (WARNING) information in the error report is displayed by default
Tab_width The default tab width is equivalent to a few spaces
Zend_ca_path the configuration options used by the Zend encoding standard, pointing to the path where Zend Code Analyzer (Zend Coding Analyzer) resides
By default, if the command line does not specify a coding standard, Php_codesniffere uses pear as the encoding standard. You can modify the default encoding standard by using the following commands.
$ phpcs--config-set Default_standard Zend
By default, that is, if the command line does not provide a parameter in the report output format, Php_codesniffere will use the full error report format to output the check results. You can use the following commands to modify the default output format of the check results.
$ phpcs--config-set Report_format Summary
By default, the Php_codesniffere output outputs error and warning messages, you can remove the warning message on the execution phpcs with-N, or you can set show_warnings to determine whether the default is to be displayed or not.
$ phpcs--config-set show_warnings 0
By default, Php_codesniffere does not replace the tab in the checked file with a space. Specifying a tab width on the command line can be used to replace the tab in the checked file with Php_codesniffere. You can set the Config-set to allow Php_codesniffere to replace tab by default.
$ phpcs--config-set tab_width 4
Note: When Php_codesniffere has been set to replace tab by default, specifying Tab_width as 0 on the command line will let php_codesniffere stop replacing tab.
The Zend encoding standard contains a sniff using the Zend Code Analyzer (Zend Coding Analyzer), which tells Zend_ca_path the path of the Code Analyzer using the Zend configuration option.
$ phpcs--config-set Zend_ca_path/path/to/zendcodeanalyzer
Specifies the file type (extension) to be checked by the Php_codesniffer
By default, Php_codesniffer checks the. Inc and. PHP files. That is, if you specify a directory for Php_codesniffer to check, only files with an Inc and PHP extension will be checked. You can set which type of extension files on the command line by using the extensions parameter to require php_codesniffer checking. $ phpcs--extensions=php/path/to/code Only check files in this directory with PHP extensions
$ phpcs--extensions=php,inc,lib/path/to/code Check all files in this directory with Php,inc,lib extensions
Note: This parameter does not apply to specifying a file directly on the command line (rather than a file directory), because in this case Php_codesniffer will ignore the extension of all files.
$ phpcs--extensions=inc sgl_06x/www/index.php sgl_06x/www/rpc/server.php The php file is still checked while the INC is specified
Ignoring the file extension is an attribute of php_codesniffer and the only way to check for files that do not have an extension file. If you give Phpcs a file directory as a parameter, then the file in this directory that does not have an extension will not be checked, if you want to check, you can only one check.
let Php_codesniffer ignore some of these special files when checking a large number of files
When Php_codesniffer checks a large number of files, we may not want to php_codesniffer check some of these special files. You can use the Ignore parameter to specify the matching pattern of the file name, and all file names that match the pattern will be ignored without checking.
$ phpcs--ignore=*/tests/*,*/data/*/path/to/code
In fact, there are some more functions, but I do not think it necessary to see, will use the above almost, or scare people will be no one to use .... It's a good thing. It's good for the company to use it well.
Here to remind, do not look at the error report is English to give up ha, in fact, not difficult, really not Google Bai.
Original address: http://bbs.lampbrother.net/read-htm-tid-152445.html reading (38) | Comments (0) | Forwarding (0) | 0
The League of Heroes in brother Lian
Next: The most complete Twitter Bootstrap development resource list related popular articles C + + will unsigned char array ... some of the predefined meanings of Linux kernel ... US RT Server leased Imitation Card website ... The registration of foreign companies in Beijing needs those flows ... text segment, data section, BSS segment, heap and stack ... phpstudy 2013 download, PHP5 development ... Grass harmonious Liu Community caoliushequ ... Types of Ganoderma lucidum and pictures for PHP add GD library support fall Melancholy everyone is using what to manage Hadoop set ... Has the website been hanged, added some programs ... Nginx how to guarantee not to go to the downtime of the ... Everyone talk about MySQL client and server ... Why do the following code output 5?...--> leave something for the host? ~ Comments Hot Discussion