C.67 PhpCodeSnifferTask

This task runs PHP_CodeSniffer to detect violations of a defined set of coding standards.

Table C.86: Attributes

standardStringThe list of coding standards to test against. Separated by space, comma or semicolon.GenericNo
formatStringThe 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.
showSniffsBooleanPrint the list of used sniffs.falseNo
showWarningsBooleanPrint warnings.trueNo
showSourcesBooleanFlag that determines whether to show sources or not.trueNo
propertyNameStringThe name of the property to set. This will be populated with the names of the sniff that were used.n/aNo
docGeneratorStringThe name of the doc generator (HTML, Text).n/aNo
docFileStringPath to write output file to. If not set documentation will be written to STDOUT when docGenerator is set.n/aNo
fileStringThe file or folder to check (usually the nested tag fileset is used instead).falseEither this attribute or the nested tag fileset is required.
sniffsStringThe list of allowed sniffs (separated by space, comma or semicolon). The sniffs must be part of the chosen standard.n/aNo
verbosityIntegerThe verbosity level of CodeSniffer where level 1 prints progress information and level 2 prints developer debug information.0No
encodingStringThe encoding of the files to checkiso-8859-1No
tabWidthIntegerReplaces tabs with the given number of spaces. If zero no replacing is done.0No
reportWidthIntegerThe max. width for the report.80No
allowedFileExtensionsStringThe allowed file extensions / file types to process. Separated by space, comma or semicolon.php, inc, js, cssNo
allowedTypesStringThe 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
ignorePatternsStringThe patterns to ignore files and folders (separated by space, comma or semicolon) when a directory is specified in the file attribute.n/aNo
noSubdirectoriesBooleanDo not recurse into subdirectories when a directory is specified in the file attribute.falseNo
haltonerrorBooleanStop the build process if errors occurred during the run.falseNo
haltonwarningBooleanStop the build process if warnings occurred during the run.falseNo
skipversioncheckBooleanSkips the version check when the task starts.falseNo
cachefileStringIf set, enables writing of last-modified times to cachefile, to speed up processing of files that rarely changenoneNo

C.67.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.

  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.

  <fileset dir="/path/to/source-files">
    <include name="**/*.php"/>
  <config name="zend_ca_path" value="/path/to/ZendStudio/bin/ZendCodeAnalyzer"/>
  <formatter type="full" usefile="false"/>
  <formatter type="checkstyle" outfile="/path/to/checkstyle.xml"/>

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.

  <formatter type="checkstyle" outfile="/path/to/checkstyle.xml"/>

Checks all files in the directory file matching the allowed file extension with the custom Foo standard and prints the summary report without warnings.

  allowedFileExtensions="php php5 inc">
    <config name="installed_paths" value="/path/to/Standards/directory"/>

C.67.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.87: Attributes

    nameStringName of the configuration parameter.n/aYes
    valueStringValue 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.88: Attributes

    typeStringThe output format. Accepts the same values as the format attribute (default, xml, checkstyle, csv, report, summary & doc).n/aYes
    usefileBooleanBoolean that determines whether output should be sent to a file.trueNo
    outfileStringPath to write output file to.n/aYes, if usefile is true.