cvs: peardoc /en/package/php/php-codesniffer advanced-usage.xml
| From: | Greg Sherwood | Date: | Tue, 16 Jan 2007 05:02:24 +0000 |
| Subject: | cvs: peardoc /en/package/php/php-codesniffer advanced-usage.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-9317@lists.php.net to get a copy of this message | ||
squiz Tue Jan 16 05:02:24 2007 UTC
Modified files:
/peardoc/en/package/php/php-codesniffer advanced-usage.xml
Log:
Advanced usage page now has docs for the --entensions, -vv and -vvv command line args.
http://cvs.php.net/viewvc.cgi/peardoc/en/package/php/php-codesniffer/advanced-usage.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/php/php-codesniffer/advanced-usage.xml diff -u peardoc/en/package/php/php-codesniffer/advanced-usage.xml:1.1 peardoc/en/package/php/php-codesniffer/advanced-usage.xml:1.2 --- peardoc/en/package/php/php-codesniffer/advanced-usage.xml:1.1 Fri Jan 12 05:18:32 2007 +++ peardoc/en/package/php/php-codesniffer/advanced-usage.xml Tue Jan 16 05:02:24 2007 @@ -1,24 +1,290 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.php.php-codesniffer.advanced-usage"> <refnamediv> <refname>Advanced Usage</refname> <refpurpose>Advanced usage information</refpurpose> </refnamediv> - <refsect1> + <refsect1 id="package.php.php-codesniffer.advanced-usage.valid-file-extensions"> <title>Specifying Valid File Extensions</title> - <warning><simpara>This functionality is currently not documented</simpara></warning> + <para> + By default, PHP_CodeSniffer will check any file it finds with a <literal>.inc</literal> or <literal>.php</literal> extension. Sometimes, this means that PHP_CodeSniffer is not checking enough of your files. Sometimes, the opposite is true. PHP_CodeSniffer allows you to specify a list of valid file extensions using the <literal>--extensions</literal> command line argument. Extensions are separated by commas. + </para> + <example> + <title>Checking <literal>.php</literal> files only</title> + <screen> + <userinput> +<![CDATA[ +$ phpcs --extensions=php /path/to/code +]]> + </userinput> + </screen> + </example> + <example> + <title>Checking <literal>.php</literal>, <literal>.inc</literal> and <literal>.lib</literal> files only</title> + <screen> + <userinput> +<![CDATA[ +$ phpcs --extensions=php,inc,lib /path/to/code +]]> + </userinput> + </screen> + </example> + <note> + <simpara> + If you have asked PHP_CodeSniffer to check a specific file rather than an entire directory, the extension of the specified file will be ignored. The file will be checked even if it has an invalid extension or no extension at all. + </simpara> + <simpara> + In the following example, the main.inc file will be checked by PHP_CodeSniffer even though the <literal>--extensions</literal> command line argument specifies that only <literal>.php</literal> files should be checked. + </simpara> + <example> + <title>Extension ignored when checking specific file</title> + <screen> + <userinput> +<![CDATA[ +$ phpcs --extensions=php /path/to/code/main.inc +]]> + </userinput> + </screen> + </example> + </note> + <note> + <simpara> + The ignoring of file extensions for specific files is a feature of PHP_CodeSniffer and is the only way to check files without an extension. If you check an entire directory of files, all files without extensions will be ignored, so you must check each of these file separately. + </simpara> + </note> </refsect1> - <refsect1> + + + + <refsect1 id="package.php.php-codesniffer.advanced-usage.verbose-tokeniser-output"> <title>Printing Verbose Tokeniser Output</title> - <warning><simpara>This functionality is currently not documented</simpara></warning> + <note> + <simpara> + This feature is provided for debugging purposes only. Using this feature will dramatically increase screen output and script running time. + </simpara> + </note> + <para> + PHP_CodeSniffer contains multiple verbosity levels. Level 2 (indicated by the command line argument <literal>-vv</literal>) will print all verbosity information for level 1 (file specific token and line counts with running times) as well as verbose tokeniser output. + </para> + <para> + The output of the PHP_CodeSniffer tokeniser shows the step-by-step creation of the <emphasis>scope map</emphasis> and the <emphasis>level map</emphasis>. + </para> + + <refsect2 id="package.php.php-codesniffer.advanced-usage.verbose-tokeniser-output.scope-map"> + <title>The Scope Map</title> + <para> + The scope map is best explained with an example. For the following file: + </para> + <para> + <programlisting role="php"> +<![CDATA[ +<?php +if ($condition) { + echo 'Condition was true'; +} +?> +]]> + </programlisting> + </para> + <para> + The scope map output is: + </para> + <example> + <title>Sample scope map output</title> + <screen> +<![CDATA[ +*** START SCOPE MAP *** +Start scope map at 1: T_IF => if +Process token 2 []: T_WHITESPACE => +Process token 3 []: T_OPEN_PARENTHESIS => ( +Process token 6 []: T_WHITESPACE => +Process token 7 []: T_OPEN_CURLY_BRACKET => { +=> Found scope opener for 1 (T_IF) +Process token 8 [opener:7;]: T_WHITESPACE => \n +Process token 9 [opener:7;]: T_WHITESPACE => +Process token 10 [opener:7;]: T_ECHO => echo +Process token 11 [opener:7;]: T_WHITESPACE => +Process token 12 [opener:7;]: T_CONSTANT_ENCAPSED_STRING => 'Condition was true' +Process token 13 [opener:7;]: T_SEMICOLON => ; +Process token 14 [opener:7;]: T_WHITESPACE => \n +Process token 15 [opener:7;]: T_CLOSE_CURLY_BRACKET => } +=> Found scope closer for 1 (T_IF) +*** END SCOPE MAP *** +]]> + </screen> + </example> + <para> + The scope map output above shows the following pieces of information about the file: + <itemizedlist> + <listitem> + <para>A scope token, <literal>if</literal>, was found at token 1 (note that token 0 is the open PHP tag).</para> + </listitem> + <listitem> + <para>The opener for the <literal>if</literal> statement, the open curly brace, was found at token 7.</para> + </listitem> + <listitem> + <para>The closer for the <literal>if</literal> statement, the close curly brace, was found at token 15.</para> + </listitem> + <listitem> + <para>Tokens 8 - 15 are all included in the scope set by the scope opener at token 7, the open curly brace. This indicates that these tokens are all within the <literal>if</literal> statement.</para> + </listitem> + </itemizedlist> + </para> + <para> + The scope map output is most useful when debugging PHP_CodeSniffer's scope map, which is critically important to the successful checking of a file, but is also useful for checking the type of a particular token. For example, if you are unsure of the token type for an opening curly brace, the scope map output shows you that the type is <constant>T_OPEN_CURLY_BRACKET</constant> and not, for example, <constant>T_OPEN_CURLY_BRACE</constant>. + </para> + </refsect2> + + <refsect2 id="package.php.php-codesniffer.advanced-usage.verbose-tokeniser-output.level-map"> + <title>The Level Map</title> + <para> + The level map is best explained with an example. For the following file: + </para> + <para> + <programlisting role="php"> +<![CDATA[ +<?php +if ($condition) { + echo 'Condition was true'; +} +?> +]]> + </programlisting> + </para> + <para> + The level map output is: + </para> + <example> + <title>Sample level map output</title> + <screen> +<![CDATA[ + *** START LEVEL MAP *** +Process token 0 on line 1 [lvl:0;]: T_OPEN_TAG => <?php\n +Process token 1 on line 2 [lvl:0;]: T_IF => if +Process token 2 on line 2 [lvl:0;]: T_WHITESPACE => +Process token 3 on line 2 [lvl:0;]: T_OPEN_PARENTHESIS => ( +Process token 4 on line 2 [lvl:0;]: T_VARIABLE => $condition +Process token 5 on line 2 [lvl:0;]: T_CLOSE_PARENTHESIS => ) +Process token 6 on line 2 [lvl:0;]: T_WHITESPACE => +Process token 7 on line 2 [lvl:0;]: T_OPEN_CURLY_BRACKET => { +=> Found scope opener for 1 (T_IF) + * level increased * + * token 1 (T_IF) added to conditions array * + Process token 8 on line 2 [lvl:1;conds;T_IF;]: T_WHITESPACE => \n + Process token 9 on line 3 [lvl:1;conds;T_IF;]: T_WHITESPACE => + Process token 10 on line 3 [lvl:1;conds;T_IF;]: T_ECHO => echo + Process token 11 on line 3 [lvl:1;conds;T_IF;]: T_WHITESPACE => + Process token 12 on line 3 [lvl:1;conds;T_IF;]: T_CONSTANT_ENCAPSED_STRING => 'Condition was true' + Process token 13 on line 3 [lvl:1;conds;T_IF;]: T_SEMICOLON => ; + Process token 14 on line 3 [lvl:1;conds;T_IF;]: T_WHITESPACE => \n + Process token 15 on line 4 [lvl:1;conds;T_IF;]: T_CLOSE_CURLY_BRACKET => } + => Found scope closer for 7 (T_OPEN_CURLY_BRACKET) + * token T_IF removed from conditions array * + * level decreased * +Process token 16 on line 4 [lvl:0;]: T_WHITESPACE => \n +Process token 17 on line 5 [lvl:0;]: T_CLOSE_TAG => ?>\n +*** END LEVEL MAP *** +]]> + </screen> + </example> + <para> + The level map output above shows the following pieces of information about the file: + <itemizedlist> + <listitem> + <para>A scope opener, an open curly brace, was found at token 7 and opened the scope for an <literal>if</literal> statement, defined at token 1.</para> + </listitem> + <listitem> + <para>Tokens 8 - 15 are all included in the scope set by the scope opener at token 7, the open curly brace. All these tokens are at level 1, indicating that they are enclosed in 1 scope condition, and all these tokens are enclosed in a single condition; an <literal>if</literal> statement.</para> + </listitem> + </itemizedlist> + </para> + <para> + The level map is most commonly used to determine indentation rules (eg. a token 4 levels deep requires 16 spaces of indentation) or to determine if a particular token is within a particular scope (eg. a <literal>function</literal> keyword is within a class scope, making it a method). + </para> + </refsect2> + </refsect1> - <refsect1> - <title>Printing Verbose Sniffing Output</title> - <warning><simpara>This functionality is currently not documented</simpara></warning> + + + + <refsect1 id="package.php.php-codesniffer.advanced-usage.verbose-token-processing-output"> + <title>Printing Verbose Token Processing Output</title> + <note> + <simpara> + This feature is provided for debugging purposes only. Using this feature will dramatically increase screen output and script running time. + </simpara> + </note> + <para> + PHP_CodeSniffer contains multiple verbosity levels. Level 3 (indicated by the command line argument <literal>-vvv</literal>) will print all verbosity information for level 1 (file specific token and line counts with running times), level 2 (tokeniser output) as well as token processing output with sniff running times. + </para> + <para> + The token processing output is best explained with an example. For the following file: + </para> + <para> + <programlisting role="php"> +<![CDATA[ +<?php +if ($condition) { + echo 'Condition was true'; +} +?> +]]> + </programlisting> + </para> + <para> + The token processing output is: + </para> + <para> + <example> + <title>Sample token processing output</title> + <screen> +<![CDATA[ +*** START TOKEN PROCESSING *** +Process token 0: T_OPEN_TAG => <?php\n + Processing PEAR_Sniffs_Commenting_FileCommentSniff... DONE in 0.001 seconds + Processing PEAR_Sniffs_Files_LineLengthSniff... DONE in 0.0004 seconds + Processing PEAR_Sniffs_PHP_DisallowShortOpenTagSniff... DONE in 0.0001 seconds +Process token 1: T_IF => if + Processing PEAR_Sniffs_ControlStructures_ControlSignatureSniff... DONE in 0.0008 seconds + Processing PEAR_Sniffs_WhiteSpace_ScopeClosingBraceSniff... DONE in 0.0248 seconds + Processing PEAR_Sniffs_WhiteSpace_ScopeIndentSniff... DONE in 0.0004 seconds +Process token 2: T_WHITESPACE => +Process token 3: T_OPEN_PARENTHESIS => ( +Process token 4: T_VARIABLE => $condition +Process token 5: T_CLOSE_PARENTHESIS => ) +Process token 6: T_WHITESPACE => +Process token 7: T_OPEN_CURLY_BRACKET => { +Process token 8: T_WHITESPACE => \n +Process token 9: T_WHITESPACE => +Process token 10: T_ECHO => echo +Process token 11: T_WHITESPACE => +Process token 12: T_CONSTANT_ENCAPSED_STRING => 'Condition was true' +Process token 13: T_SEMICOLON => ; +Process token 14: T_WHITESPACE => \n +Process token 15: T_CLOSE_CURLY_BRACKET => } +Process token 16: T_WHITESPACE => \n +Process token 17: T_CLOSE_TAG => ?>\n +*** END TOKEN PROCESSING *** +]]> + </screen> + </example> + </para> + <para> + Every token processed is shown, along with its ID, type and contents. For each token, all sniffs that were executed on the token are displayed, along with the running time. + </para> + <para> + For example, the output above shows us that token 1, an <literal>if</literal> keyword, had 3 sniffs executed on it; the ControlSignature sniff, the ScopeClosingBrace sniff and the ScopeIndent sniff. Each was executed fairly quickly, but the slowest was the ScopeClosingBrace sniff, taking 0.0248 seconds to process that token. + </para> + <para> + The other interesting piece of information we get from the output above is that only 2 tokens in the whole file had sniffs executed on them; tokens 0 and 1. This is normal behavior for PHP_CodeSniffer as most sniffs listen for a very specific and rarely used token and then execute on it and a number of tokens following it. + </para> + <para> + For example, the ScopeIndentSniff executes on the <literal>if</literal> statement's token only, but actually checks the indentation of every line within the <literal>if</literal> statement. The sniff uses the <link linkend="package.php.php-codesniffer.advanced-usage.verbose-tokeniser-output.scope-map">scope map</link> to find all tokens within the <literal>if</literal> statement. + </para> </refsect1> </refentry>
http://cvs.php.net/viewvc.cgi/peardoc/en/package/php/php-codesniffer/advanced-usage.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/php/php-codesniffer/advanced-usage.xml diff -u peardoc/en/package/php/php-codesniffer/advanced-usage.xml:1.1 peardoc/en/package/php/php-codesniffer/advanced-usage.xml:1.2 --- peardoc/en/package/php/php-codesniffer/advanced-usage.xml:1.1 Fri Jan 12 05:18:32 2007 +++ peardoc/en/package/php/php-codesniffer/advanced-usage.xml Tue Jan 16 05:02:24 2007 @@ -1,24 +1,290 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.php.php-codesniffer.advanced-usage"> <refnamediv> <refname>Advanced Usage</refname> <refpurpose>Advanced usage information</refpurpose> </refnamediv> - <refsect1> + <refsect1 id="package.php.php-codesniffer.advanced-usage.valid-file-extensions"> <title>Specifying Valid File Extensions</title> - <warning><simpara>This functionality is currently not documented</simpara></warning> + <para> + By default, PHP_CodeSniffer will check any file it finds with a <literal>.inc</literal> or <literal>.php</literal> extension. Sometimes, this means that PHP_CodeSniffer is not checking enough of your files. Sometimes, the opposite is true. PHP_CodeSniffer allows you to specify a list of valid file extensions using the <literal>--extensions</literal> command line argument. Extensions are separated by commas. + </para> + <example> + <title>Checking <literal>.php</literal> files only</title> + <screen> + <userinput> +<![CDATA[ +$ phpcs --extensions=php /path/to/code +]]> + </userinput> + </screen> + </example> + <example> + <title>Checking <literal>.php</literal>, <literal>.inc</literal> and <literal>.lib</literal> files only</title> + <screen> + <userinput> +<![CDATA[ +$ phpcs --extensions=php,inc,lib /path/to/code +]]> + </userinput> + </screen> + </example> + <note> + <simpara> + If you have asked PHP_CodeSniffer to check a specific file rather than an entire directory, the extension of the specified file will be ignored. The file will be checked even if it has an invalid extension or no extension at all. + </simpara> + <simpara> + In the following example, the main.inc file will be checked by PHP_CodeSniffer even though the <literal>--extensions</literal> command line argument specifies that only <literal>.php</literal> files should be checked. + </simpara> + <example> + <title>Extension ignored when checking specific file</title> + <screen> + <userinput> +<![CDATA[ +$ phpcs --extensions=php /path/to/code/main.inc +]]> + </userinput> + </screen> + </example> + </note> + <note> + <simpara> + The ignoring of file extensions for specific files is a feature of PHP_CodeSniffer and is the only way to check files without an extension. If you check an entire directory of files, all files without extensions will be ignored, so you must check each of these file separately. + </simpara> + </note> </refsect1> - <refsect1> + + + + <refsect1 id="package.php.php-codesniffer.advanced-usage.verbose-tokeniser-output"> <title>Printing Verbose Tokeniser Output</title> - <warning><simpara>This functionality is currently not documented</simpara></warning> + <note> + <simpara> + This feature is provided for debugging purposes only. Using this feature will dramatically increase screen output and script running time. + </simpara> + </note> + <para> + PHP_CodeSniffer contains multiple verbosity levels. Level 2 (indicated by the command line argument <literal>-vv</literal>) will print all verbosity information for level 1 (file specific token and line counts with running times) as well as verbose tokeniser output. + </para> + <para> + The output of the PHP_CodeSniffer tokeniser shows the step-by-step creation of the <emphasis>scope map</emphasis> and the <emphasis>level map</emphasis>. + </para> + + <refsect2 id="package.php.php-codesniffer.advanced-usage.verbose-tokeniser-output.scope-map"> + <title>The Scope Map</title> + <para> + The scope map is best explained with an example. For the following file: + </para> + <para> + <programlisting role="php"> +<![CDATA[ +<?php +if ($condition) { + echo 'Condition was true'; +} +?> +]]> + </programlisting> + </para> + <para> + The scope map output is: + </para> + <example> + <title>Sample scope map output</title> + <screen> +<![CDATA[ +*** START SCOPE MAP *** +Start scope map at 1: T_IF => if +Process token 2 []: T_WHITESPACE => +Process token 3 []: T_OPEN_PARENTHESIS => ( +Process token 6 []: T_WHITESPACE => +Process token 7 []: T_OPEN_CURLY_BRACKET => { +=> Found scope opener for 1 (T_IF) +Process token 8 [opener:7;]: T_WHITESPACE => \n +Process token 9 [opener:7;]: T_WHITESPACE => +Process token 10 [opener:7;]: T_ECHO => echo +Process token 11 [opener:7;]: T_WHITESPACE => +Process token 12 [opener:7;]: T_CONSTANT_ENCAPSED_STRING => 'Condition was true' +Process token 13 [opener:7;]: T_SEMICOLON => ; +Process token 14 [opener:7;]: T_WHITESPACE => \n +Process token 15 [opener:7;]: T_CLOSE_CURLY_BRACKET => } +=> Found scope closer for 1 (T_IF) +*** END SCOPE MAP *** +]]> + </screen> + </example> + <para> + The scope map output above shows the following pieces of information about the file: + <itemizedlist> + <listitem> + <para>A scope token, <literal>if</literal>, was found at token 1 (note that token 0 is the open PHP tag).</para> + </listitem> + <listitem> + <para>The opener for the <literal>if</literal> statement, the open curly brace, was found at token 7.</para> + </listitem> + <listitem> + <para>The closer for the <literal>if</literal> statement, the close curly brace, was found at token 15.</para> + </listitem> + <listitem> + <para>Tokens 8 - 15 are all included in the scope set by the scope opener at token 7, the open curly brace. This indicates that these tokens are all within the <literal>if</literal> statement.</para> + </listitem> + </itemizedlist> + </para> + <para> + The scope map output is most useful when debugging PHP_CodeSniffer's scope map, which is critically important to the successful checking of a file, but is also useful for checking the type of a particular token. For example, if you are unsure of the token type for an opening curly brace, the scope map output shows you that the type is <constant>T_OPEN_CURLY_BRACKET</constant> and not, for example, <constant>T_OPEN_CURLY_BRACE</constant>. + </para> + </refsect2> + + <refsect2 id="package.php.php-codesniffer.advanced-usage.verbose-tokeniser-output.level-map"> + <title>The Level Map</title> + <para> + The level map is best explained with an example. For the following file: + </para> + <para> + <programlisting role="php"> +<![CDATA[ +<?php +if ($condition) { + echo 'Condition was true'; +} +?> +]]> + </programlisting> + </para> + <para> + The level map output is: + </para> + <example> + <title>Sample level map output</title> + <screen> +<![CDATA[ + *** START LEVEL MAP *** +Process token 0 on line 1 [lvl:0;]: T_OPEN_TAG => <?php\n +Process token 1 on line 2 [lvl:0;]: T_IF => if +Process token 2 on line 2 [lvl:0;]: T_WHITESPACE => +Process token 3 on line 2 [lvl:0;]: T_OPEN_PARENTHESIS => ( +Process token 4 on line 2 [lvl:0;]: T_VARIABLE => $condition +Process token 5 on line 2 [lvl:0;]: T_CLOSE_PARENTHESIS => ) +Process token 6 on line 2 [lvl:0;]: T_WHITESPACE => +Process token 7 on line 2 [lvl:0;]: T_OPEN_CURLY_BRACKET => { +=> Found scope opener for 1 (T_IF) + * level increased * + * token 1 (T_IF) added to conditions array * + Process token 8 on line 2 [lvl:1;conds;T_IF;]: T_WHITESPACE => \n + Process token 9 on line 3 [lvl:1;conds;T_IF;]: T_WHITESPACE => + Process token 10 on line 3 [lvl:1;conds;T_IF;]: T_ECHO => echo + Process token 11 on line 3 [lvl:1;conds;T_IF;]: T_WHITESPACE => + Process token 12 on line 3 [lvl:1;conds;T_IF;]: T_CONSTANT_ENCAPSED_STRING => 'Condition was true' + Process token 13 on line 3 [lvl:1;conds;T_IF;]: T_SEMICOLON => ; + Process token 14 on line 3 [lvl:1;conds;T_IF;]: T_WHITESPACE => \n + Process token 15 on line 4 [lvl:1;conds;T_IF;]: T_CLOSE_CURLY_BRACKET => } + => Found scope closer for 7 (T_OPEN_CURLY_BRACKET) + * token T_IF removed from conditions array * + * level decreased * +Process token 16 on line 4 [lvl:0;]: T_WHITESPACE => \n +Process token 17 on line 5 [lvl:0;]: T_CLOSE_TAG => ?>\n +*** END LEVEL MAP *** +]]> + </screen> + </example> + <para> + The level map output above shows the following pieces of information about the file: + <itemizedlist> + <listitem> + <para>A scope opener, an open curly brace, was found at token 7 and opened the scope for an <literal>if</literal> statement, defined at token 1.</para> + </listitem> + <listitem> + <para>Tokens 8 - 15 are all included in the scope set by the scope opener at token 7, the open curly brace. All these tokens are at level 1, indicating that they are enclosed in 1 scope condition, and all these tokens are enclosed in a single condition; an <literal>if</literal> statement.</para> + </listitem> + </itemizedlist> + </para> + <para> + The level map is most commonly used to determine indentation rules (eg. a token 4 levels deep requires 16 spaces of indentation) or to determine if a particular token is within a particular scope (eg. a <literal>function</literal> keyword is within a class scope, making it a method). + </para> + </refsect2> + </refsect1> - <refsect1> - <title>Printing Verbose Sniffing Output</title> - <warning><simpara>This functionality is currently not documented</simpara></warning> + + + + <refsect1 id="package.php.php-codesniffer.advanced-usage.verbose-token-processing-output"> + <title>Printing Verbose Token Processing Output</title> + <note> + <simpara> + This feature is provided for debugging purposes only. Using this feature will dramatically increase screen output and script running time. + </simpara> + </note> + <para> + PHP_CodeSniffer contains multiple verbosity levels. Level 3 (indicated by the command line argument <literal>-vvv</literal>) will print all verbosity information for level 1 (file specific token and line counts with running times), level 2 (tokeniser output) as well as token processing output with sniff running times. + </para> + <para> + The token processing output is best explained with an example. For the following file: + </para> + <para> + <programlisting role="php"> +<![CDATA[ +<?php +if ($condition) { + echo 'Condition was true'; +} +?> +]]> + </programlisting> + </para> + <para> + The token processing output is: + </para> + <para> + <example> + <title>Sample token processing output</title> + <screen> +<![CDATA[ +*** START TOKEN PROCESSING *** +Process token 0: T_OPEN_TAG => <?php\n + Processing PEAR_Sniffs_Commenting_FileCommentSniff... DONE in 0.001 seconds + Processing PEAR_Sniffs_Files_LineLengthSniff... DONE in 0.0004 seconds + Processing PEAR_Sniffs_PHP_DisallowShortOpenTagSniff... DONE in 0.0001 seconds +Process token 1: T_IF => if + Processing PEAR_Sniffs_ControlStructures_ControlSignatureSniff... DONE in 0.0008 seconds + Processing PEAR_Sniffs_WhiteSpace_ScopeClosingBraceSniff... DONE in 0.0248 seconds + Processing PEAR_Sniffs_WhiteSpace_ScopeIndentSniff... DONE in 0.0004 seconds +Process token 2: T_WHITESPACE => +Process token 3: T_OPEN_PARENTHESIS => ( +Process token 4: T_VARIABLE => $condition +Process token 5: T_CLOSE_PARENTHESIS => ) +Process token 6: T_WHITESPACE => +Process token 7: T_OPEN_CURLY_BRACKET => { +Process token 8: T_WHITESPACE => \n +Process token 9: T_WHITESPACE => +Process token 10: T_ECHO => echo +Process token 11: T_WHITESPACE => +Process token 12: T_CONSTANT_ENCAPSED_STRING => 'Condition was true' +Process token 13: T_SEMICOLON => ; +Process token 14: T_WHITESPACE => \n +Process token 15: T_CLOSE_CURLY_BRACKET => } +Process token 16: T_WHITESPACE => \n +Process token 17: T_CLOSE_TAG => ?>\n +*** END TOKEN PROCESSING *** +]]> + </screen> + </example> + </para> + <para> + Every token processed is shown, along with its ID, type and contents. For each token, all sniffs that were executed on the token are displayed, along with the running time. + </para> + <para> + For example, the output above shows us that token 1, an <literal>if</literal> keyword, had 3 sniffs executed on it; the ControlSignature sniff, the ScopeClosingBrace sniff and the ScopeIndent sniff. Each was executed fairly quickly, but the slowest was the ScopeClosingBrace sniff, taking 0.0248 seconds to process that token. + </para> + <para> + The other interesting piece of information we get from the output above is that only 2 tokens in the whole file had sniffs executed on them; tokens 0 and 1. This is normal behavior for PHP_CodeSniffer as most sniffs listen for a very specific and rarely used token and then execute on it and a number of tokens following it. + </para> + <para> + For example, the ScopeIndentSniff executes on the <literal>if</literal> statement's token only, but actually checks the indentation of every line within the <literal>if</literal> statement. The sniff uses the <link linkend="package.php.php-codesniffer.advanced-usage.verbose-tokeniser-output.scope-map">scope map</link> to find all tokens within the <literal>if</literal> statement. + </para> </refsect1> </refentry>