| | 858 | |
| | 859 | <h2><a name="PhpCodeSnifferTask"></a>PhpCodeSnifferTask</h2> |
| | 860 | <p>This task runs <a href="http://pear.php.net/package/PHP_CodeSniffer" target="_blank">PHP_CodeSniffer</a> to detect violations of a defined set of coding standards.</p> |
| | 861 | <h3>Attributes</h3> |
| | 862 | <table> |
| | 863 | <thead> |
| | 864 | <tr> |
| | 865 | <th>Name</th> |
| | 866 | <th>Type</th> |
| | 867 | <th>Description</th> |
| | 868 | <th>Default</th> |
| | 869 | <th>Required</th> |
| | 870 | </tr> |
| | 871 | </thead> |
| | 872 | <tbody> |
| | 873 | <tr> |
| | 874 | <td>standard</td> |
| | 875 | <td>String</td> |
| | 876 | <td>The name of the standard or an absolute path to an external standard to check for.</td> |
| | 877 | <td>Generic</td> |
| | 878 | <td>No</td> |
| | 879 | </tr> |
| | 880 | <tr> |
| | 881 | <td>outputFormat</td> |
| | 882 | <td>String</td> |
| | 883 | <td>The output format. The <em>default</em> format is specified in the task itself. Additionally the formats of CodeSniffer can be choosen: <em>xml</em>, <em>checkstyle</em>, <em>csv</em>, <em>report</em> and <em>summary</em>. A special case is the format <em>doc</em> which generates the documentation of the standard.</td> |
| | 884 | <td>default</td> |
| | 885 | <td>No</td> |
| | 886 | </tr> |
| | 887 | <tr> |
| | 888 | <td>showSniffs</td> |
| | 889 | <td>Boolean</td> |
| | 890 | <td>Print the list of used sniffs.</td> |
| | 891 | <td>false</td> |
| | 892 | <td>No</td> |
| | 893 | </tr> |
| | 894 | <tr> |
| | 895 | <td>showWarnings</td> |
| | 896 | <td>Boolean</td> |
| | 897 | <td>Print warnings.</td> |
| | 898 | <td>true</td> |
| | 899 | <td>No</td> |
| | 900 | </tr> |
| | 901 | <tr> |
| | 902 | <td>file</td> |
| | 903 | <td>String</td> |
| | 904 | <td>The file or folder to check (usally the nested tag <em>fileset</em> is used instead).</td> |
| | 905 | <td>false</td> |
| | 906 | <td>Either this attribute or the nested tag <em>fileset</em> is required.</td> |
| | 907 | </tr> |
| | 908 | <tr> |
| | 909 | <td>sniffs</td> |
| | 910 | <td>String</td> |
| | 911 | <td>The list of allowed sniffs (separated by space, comma or semicolon). The sniffs must be part of the choosen standard.</td> |
| | 912 | <td>n/a</td> |
| | 913 | <td>No</td> |
| | 914 | </tr> |
| | 915 | <tr> |
| | 916 | <td>verbosity</td> |
| | 917 | <td>Integer</td> |
| | 918 | <td>The verbosity level of CodeSniffer where level 1 prints progress information and level 2 prints developer debug information.</td> |
| | 919 | <td>0</td> |
| | 920 | <td>No</td> |
| | 921 | </tr> |
| | 922 | <tr> |
| | 923 | <td>tabWidth</td> |
| | 924 | <td>Integer</td> |
| | 925 | <td>Replaces tabs with the given number of spaces. If zero no replacing is done.</td> |
| | 926 | <td>0</td> |
| | 927 | <td>No</td> |
| | 928 | </tr> |
| | 929 | <tr> |
| | 930 | <td>allowedFileExtensions</td> |
| | 931 | <td>String</td> |
| | 932 | <td>The allowed file extensions (separated by space, comma or semicolon) when a directory is specified in the <em>file</em> attribute.</td> |
| | 933 | <td>php</td> |
| | 934 | <td>No</td> |
| | 935 | </tr> |
| | 936 | <tr> |
| | 937 | <td>ignorePatterns</td> |
| | 938 | <td>String</td> |
| | 939 | <td>The patterns to ignore files and folders (separated by space, comma or semicolon) when a directory is specified in the <em>file</em> attribute.</td> |
| | 940 | <td>n/a</td> |
| | 941 | <td>No</td> |
| | 942 | </tr> |
| | 943 | <tr> |
| | 944 | <td>noSubdirectories</td> |
| | 945 | <td>Boolean</td> |
| | 946 | <td>Do not recurse into subdirectories when a directory is specified in the <em>file</em> attribute.</td> |
| | 947 | <td>false</td> |
| | 948 | <td>No</td> |
| | 949 | </tr> |
| | 950 | </tbody> |
| | 951 | </table> |
| | 952 | <h3>Supported Nested Tags</h3> |
| | 953 | <ul> |
| | 954 | <li>fileset |
| | 955 | <p>Either this nested tag or the attribute <em>file</em> is required.</p> |
| | 956 | </li> |
| | 957 | <li>config |
| | 958 | <p>The configuration parameters which are usally loaded from the CodeSniffer.conf can be set.</p> |
| | 959 | <h3>Attributes</h3> |
| | 960 | <table> |
| | 961 | <thead> |
| | 962 | <tr> |
| | 963 | <th>Name</th> |
| | 964 | <th>Type</th> |
| | 965 | <th>Description</th> |
| | 966 | <th>Default</th> |
| | 967 | <th>Required</th> |
| | 968 | </tr> |
| | 969 | </thead> |
| | 970 | <tbody> |
| | 971 | <tr> |
| | 972 | <td>name</td> |
| | 973 | <td>String</td> |
| | 974 | <td>Name of the configuration parameter. </td> |
| | 975 | <td>n/a</td> |
| | 976 | <td>Yes</td> |
| | 977 | </tr> |
| | 978 | <tr> |
| | 979 | <td>value</td> |
| | 980 | <td>String</td> |
| | 981 | <td>Value of the configuration parameter. </td> |
| | 982 | <td>n/a</td> |
| | 983 | <td>Yes</td> |
| | 984 | </tr> |
| | 985 | </tbody> |
| | 986 | </table> |
| | 987 | </li> |
| | 988 | </ul> |
| | 989 | <h3>Examples</h3> |
| | 990 | <p>Checks all files in the directory <em>file</em> matching the allowed file extension with the <em>PEAR</em> standard and prints the <em>summary</em> report without warnings.</p> |
| | 991 | <pre><phpcodesniffer |
| | 992 | standard="PEAR" |
| | 993 | format="summary" |
| | 994 | file="/path/to/source-files" |
| | 995 | allowedFileExtensions="php php5 inc"/> |
| | 996 | </phpcodesniffer> |
| | 997 | </pre> |
| | 998 | <p>Checks all matching files in the directory <em>dir</em> with a custom external standard, sets the <em>zend_ca_path</em> configuration which may be required by one of the sniffs, prints a list of used sniffs and prints the <em>default</em> report with warnings.</p> |
| | 999 | <pre><phpunit |
| | 1000 | standard="/path/to/external-standard" |
| | 1001 | showSniffs="true" |
| | 1002 | showWarnigns="true"> |
| | 1003 | <fileset dir="/path/to/source-files"> |
| | 1004 | <include name="**/*.php"/> |
| | 1005 | </fileset> |
| | 1006 | <config name="zend_ca_path" value="/path/to/ZendStudio/bin/ZendCodeAnalyzer"> |
| | 1007 | </phpunit> |
| | 1008 | </pre> |
| | 1009 | <p>Externally stored custom standard have to follow the same naming conventions as if they were stored in the <em>Standards</em> subdirectory of PHP_CodeSniffer itself.</p> |