This task runs PHP_CodeSniffer to detect violations of a defined set of coding standards.
Table C.68: Attributes
Name | Type | Description | Default | Required |
---|---|---|---|---|
standard | String | The list of coding standards to test against. Separated by space, comma or semicolon. | Generic | No |
format | String | The output format. The full format is specified
in the task itself. Additionally all report formats of PHP_CodeSniffer
can be choosen (ex. checkstyle ,
full , summary , ...). | full | No 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 |
docGenerator | String | The name of the doc generator (HTML, Text). | n/a | No |
docFile | String | Path to write output file to. If not set documentation will be
written to STDOUT when docGenerator is set. | n/a | No |
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 choosen standard. | n/a | No |
verbosity | Integer | The verbosity level of CodeSniffer where level 1 prints progress information and level 2 prints developer debug information. | 0 | No |
encoding | String | The encoding of the files to check | iso-8859-1 | No |
tabWidth | Integer | Replaces tabs with the given number of spaces. If zero no replacing is done. | 0 | No |
reportWidth | Integer | The max. width for the report. | 80 | No |
allowedFileExtensions | String | The allowed file extensions / file types to process. Separated by space, comma or semicolon. | php, inc, js, css | No |
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/a | No |
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 |
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>
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.69: Attributes
Name | Type | Description | Default | Required |
---|---|---|---|---|
name | String | Name of the configuration parameter. | n/a | Yes |
value | String | Value of the configuration parameter. | n/a | Yes |
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.70: Attributes
Name | Type | Description | Default | Required |
---|---|---|---|---|
type | String | The output format. Accepts the same values as the
format attribute
(default , xml ,
checkstyle , csv ,
report , summary
& doc ). | n/a | Yes |
usefile | Boolean | Boolean that determines whether output should be sent to a file. | true | No |
outfile | String | Path to write output file to. | n/a | Yes, if usefile is
true . |