annotate vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children 129ea1e6d783
rev   line source
Chris@0 1 <?php
Chris@0 2 /**
Chris@0 3 * Drupal_Sniffs_Semanitcs_FunctionWatchdogSniff.
Chris@0 4 *
Chris@0 5 * @category PHP
Chris@0 6 * @package PHP_CodeSniffer
Chris@0 7 * @link http://pear.php.net/package/PHP_CodeSniffer
Chris@0 8 */
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Checks that the second argument to watchdog() is not enclosed with t().
Chris@0 12 *
Chris@0 13 * @category PHP
Chris@0 14 * @package PHP_CodeSniffer
Chris@0 15 * @link http://pear.php.net/package/PHP_CodeSniffer
Chris@0 16 */
Chris@0 17 class Drupal_Sniffs_Semantics_FunctionWatchdogSniff extends Drupal_Sniffs_Semantics_FunctionCall
Chris@0 18 {
Chris@0 19
Chris@0 20
Chris@0 21 /**
Chris@0 22 * Returns an array of function names this test wants to listen for.
Chris@0 23 *
Chris@0 24 * @return array
Chris@0 25 */
Chris@0 26 public function registerFunctionNames()
Chris@0 27 {
Chris@0 28 return array('watchdog');
Chris@0 29
Chris@0 30 }//end registerFunctionNames()
Chris@0 31
Chris@0 32
Chris@0 33 /**
Chris@0 34 * Processes this function call.
Chris@0 35 *
Chris@0 36 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
Chris@0 37 * @param int $stackPtr The position of the function call in
Chris@0 38 * the stack.
Chris@0 39 * @param int $openBracket The position of the opening
Chris@0 40 * parenthesis in the stack.
Chris@0 41 * @param int $closeBracket The position of the closing
Chris@0 42 * parenthesis in the stack.
Chris@0 43 *
Chris@0 44 * @return void
Chris@0 45 */
Chris@0 46 public function processFunctionCall(
Chris@0 47 PHP_CodeSniffer_File $phpcsFile,
Chris@0 48 $stackPtr,
Chris@0 49 $openBracket,
Chris@0 50 $closeBracket
Chris@0 51 ) {
Chris@0 52 $tokens = $phpcsFile->getTokens();
Chris@0 53 // Get the second argument passed to watchdog().
Chris@0 54 $argument = $this->getArgument(2);
Chris@0 55 if ($argument === false) {
Chris@0 56 $error = 'The second argument to watchdog() is missing';
Chris@0 57 $phpcsFile->addError($error, $stackPtr, 'WatchdogArgument');
Chris@0 58 return;
Chris@0 59 }
Chris@0 60
Chris@0 61 if ($tokens[$argument['start']]['code'] === T_STRING
Chris@0 62 && $tokens[$argument['start']]['content'] === 't'
Chris@0 63 ) {
Chris@0 64 $error = 'The second argument to watchdog() should not be enclosed with t()';
Chris@0 65 $phpcsFile->addError($error, $argument['start'], 'WatchdogT');
Chris@0 66 }
Chris@0 67
Chris@0 68 $concatFound = $phpcsFile->findNext(T_STRING_CONCAT, $argument['start'], $argument['end']);
Chris@0 69 if ($concatFound !== false) {
Chris@0 70 $error = 'Concatenating translatable strings is not allowed, use placeholders instead and only one string literal';
Chris@0 71 $phpcsFile->addError($error, $concatFound, 'Concat');
Chris@0 72 }
Chris@0 73
Chris@0 74 }//end processFunctionCall()
Chris@0 75
Chris@0 76
Chris@0 77 }//end class