Sniff.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Represents a PHP_CodeSniffer sniff for sniffing coding standards.
  4. *
  5. * PHP version 5
  6. *
  7. * @category PHP
  8. * @package PHP_CodeSniffer
  9. * @author Greg Sherwood <gsherwood@squiz.net>
  10. * @author Marc McIntyre <mmcintyre@squiz.net>
  11. * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
  12. * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
  13. * @version CVS: $Id: Sniff.php 247324 2007-11-30 01:18:41Z squiz $
  14. * @link http://pear.php.net/package/PHP_CodeSniffer
  15. */
  16. /**
  17. * Represents a PHP_CodeSniffer sniff for sniffing coding standards.
  18. *
  19. * A sniff registers what token types it wishes to listen for, then, when
  20. * PHP_CodeSniffer encounters that token, the sniff is invoked and passed
  21. * information about where the token was found in the stack, and the
  22. * PHP_CodeSniffer file in which the token was found.
  23. *
  24. * @category PHP
  25. * @package PHP_CodeSniffer
  26. * @author Greg Sherwood <gsherwood@squiz.net>
  27. * @author Marc McIntyre <mmcintyre@squiz.net>
  28. * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
  29. * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
  30. * @version Release: 1.3.0RC1
  31. * @link http://pear.php.net/package/PHP_CodeSniffer
  32. */
  33. interface PHP_CodeSniffer_Sniff
  34. {
  35. /**
  36. * Registers the tokens that this sniff wants to listen for.
  37. *
  38. * An example return value for a sniff that wants to listen for whitespace
  39. * and any comments would be:
  40. *
  41. * <code>
  42. * return array(
  43. * T_WHITESPACE,
  44. * T_DOC_COMMENT,
  45. * T_COMMENT,
  46. * );
  47. * </code>
  48. *
  49. * @return array(int)
  50. * @see Tokens.php
  51. */
  52. public function register();
  53. /**
  54. * Called when one of the token types that this sniff is listening for
  55. * is found.
  56. *
  57. * The stackPtr variable indicates where in the stack the token was found.
  58. * A sniff can acquire information this token, along with all the other
  59. * tokens within the stack by first acquiring the token stack:
  60. *
  61. * <code>
  62. * $tokens = $phpcsFile->getTokens();
  63. * echo 'Encountered a '.$tokens[$stackPtr]['type'].' token';
  64. * echo 'token information: ';
  65. * print_r($tokens[$stackPtr]);
  66. * </code>
  67. *
  68. * If the sniff discovers an anomilty in the code, they can raise an error
  69. * by calling addError() on the PHP_CodeSniffer_File object, specifying an error
  70. * message and the position of the offending token:
  71. *
  72. * <code>
  73. * $phpcsFile->addError('Encountered an error', $stackPtr);
  74. * </code>
  75. *
  76. * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the
  77. * token was found.
  78. * @param int $stackPtr The position in the PHP_CodeSniffer
  79. * file's token stack where the token
  80. * was found.
  81. *
  82. * @return void
  83. */
  84. public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr);
  85. }//end interface
  86. ?>