企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# C.70 PhpCodeSnifferTask This task runs [PHP\_CodeSniffer](http://pear.php.net/package/PHP_CodeSniffer) to detect violations of a defined set of coding standards. Table C.90:聽Attributes NameTypeDescriptionDefaultRequired`standard``String`The list of coding standards to test against. Separated by space, comma or semicolon.GenericNo`format``String`The output format. The `full` format is specified in the task itself. Additionally all report formats of PHP\_CodeSniffer can be chosen (ex. `checkstyle`, `full`, `summary`, ...).fullNo Ignored if nested `formatter` elements are supplied.`showSniffs``Boolean`Print the list of used sniffs.`false`No`showWarnings``Boolean`Print warnings.`true`No`showSources``Boolean`Flag that determines whether to show sources or not.`true`No`propertyName``String`The name of the property to set. This will be populated with the names of the sniff that were used.n/aNo`docGenerator``String`The name of the doc generator (HTML, Text).n/aNo`docFile``String`Path to write output file to. If not set documentation will be written to STDOUT when `docGenerator` is set.n/aNo`file``String`The file or folder to check (usually the nested tag `fileset` is used instead).`false`Either this attribute or the nested tag `fileset` is required.`sniffs``String`The list of allowed sniffs (separated by space, comma or semicolon). The sniffs must be part of the chosen standard.n/aNo`verbosity``Integer`The verbosity level of CodeSniffer where level 1 prints progress information and level 2 prints developer debug information.0No`encoding``String`The encoding of the files to checkiso-8859-1No`tabWidth``Integer`Replaces tabs with the given number of spaces. If zero no replacing is done.0No`reportWidth``Integer`The max. width for the report.80No`allowedFileExtensions``String`The allowed file extensions / file types to process. Separated by space, comma or semicolon.php, inc, js, cssNo`allowedTypes``String`The allowed types used by PHP\_CodeSniffer::suggestType() which is used internally by some PHPCS rules (e.g. Squiz.Commenting.FunctionComment uses it to check variables / parameter types). Separated by space, comma or semicolon.n/a (PHP\_CodeSniffer default is used)No`ignorePatterns``String`The patterns to ignore files and folders (separated by space, comma or semicolon) when a directory is specified in the `file` attribute.n/aNo`noSubdirectories``Boolean`Do not recurse into subdirectories when a directory is specified in the `file` attribute.`false`No`haltonerror``Boolean`Stop the build process if errors occurred during the run.`false`No`haltonwarning``Boolean`Stop the build process if warnings occurred during the run.`false`No`skipversioncheck``Boolean`Skips the version check when the task starts.`false`No`cachefile``String`If set, enables writing of last-modified times to `cachefile`, to speed up processing of files that rarely changenoneNo C.70.1 Examples Checks all files in the directory `file` matching the allowed file extension with the `PEAR` standard and prints the `summary` report without warnings. ``` <phpcodesniffer standard="PEAR" format="summary" file="/path/to/source-files" allowedFileExtensions="php php5 inc"/> ``` Checks all matching files in the `fileset` with the `Zend` standard, sets the `zend_ca_path` configuration which may be required by one of the sniffs, prints a list of used sniffs and prints the `default` report with warnings and the `checkstyle` report to `/path/to/checkstyle.xml`. ``` <phpcodesniffer standard="Zend" showSniffs="true" showWarnings="true"> <fileset dir="/path/to/source-files"> <include name="**/*.php"/> </fileset> <config name="zend_ca_path" value="/path/to/ZendStudio/bin/ZendCodeAnalyzer"/> <formatter type="full" usefile="false"/> <formatter type="checkstyle" outfile="/path/to/checkstyle.xml"/> </phpcodesniffer> ``` Checks all files in the directory `file` with the `PEAR` standard and prints the `checkstyle` report without warnings. It also generates the documentation for the selected coding standard and writes it to the given file. ``` <phpcodesniffer standard="PEAR" file="/path/to/source-files" docGenerator="HTML" docFile="/path/to/doc.html"> <formatter type="checkstyle" outfile="/path/to/checkstyle.xml"/> </phpcodesniffer> ``` Checks all files in the directory `file` matching the allowed file extension with the custom `Foo` standard and prints the `summary` report without warnings. ``` <phpcodesniffer standard="Foo" format="summary" file="/path/to/source-files" allowedFileExtensions="php php5 inc"> <config name="installed_paths" value="/path/to/Standards/directory"/> </phpcodesniffer> ``` C.70.2 Supported Nested Tags - `fileset` Either this nested tag or the attribute `file` is required. - `config` The configuration parameters which are usually loaded from the CodeSniffer.conf can be set. Table C.91:聽Attributes NameTypeDescriptionDefaultRequired`name``String`Name of the configuration parameter.n/aYes`value``String`Value of the configuration parameter.n/aYes - `formatter` The results of the tests can be printed in different formats. Output will always be sent to a file, unless you set the `usefile` attribute to `false.` Table C.92:聽Attributes NameTypeDescriptionDefaultRequired`type``String`The output format. Accepts the same values as the `format` attribute (`default`, `xml`, `checkstyle`, `csv`, `report`, `summary` & `doc`).n/aYes`usefile``Boolean`Boolean that determines whether output should be sent to a file.`true`No`outfile``String`Path to write output file to.n/aYes, if `usefile` is `true`.