Drupal investigation

Sniff.php 3.3KB

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