comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/EmptyInstallSniff.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php 1 <?php
2 /** 2 /**
3 * Drupal_Sniffs_Semantics_EmptyInstallSniff. 3 * \Drupal\Sniffs\Semantics\EmptyInstallSniff.
4 * 4 *
5 * @category PHP 5 * @category PHP
6 * @package PHP_CodeSniffer 6 * @package PHP_CodeSniffer
7 * @link http://pear.php.net/package/PHP_CodeSniffer 7 * @link http://pear.php.net/package/PHP_CodeSniffer
8 */ 8 */
9
10 namespace Drupal\Sniffs\Semantics;
11
12 use Drupal\Sniffs\Semantics\FunctionDefinition;
13 use PHP_CodeSniffer\Files\File;
14 use PHP_CodeSniffer\Util\Tokens;
9 15
10 /** 16 /**
11 * Throws an error if hook_install() or hook_uninstall() definitions are empty. 17 * Throws an error if hook_install() or hook_uninstall() definitions are empty.
12 * 18 *
13 * @category PHP 19 * @category PHP
14 * @package PHP_CodeSniffer 20 * @package PHP_CodeSniffer
15 * @link http://pear.php.net/package/PHP_CodeSniffer 21 * @link http://pear.php.net/package/PHP_CodeSniffer
16 */ 22 */
17 class Drupal_Sniffs_Semantics_EmptyInstallSniff extends Drupal_Sniffs_Semantics_FunctionDefinition 23 class EmptyInstallSniff extends FunctionDefinition
18 { 24 {
19 25
20 26
21 /** 27 /**
22 * Process this function definition. 28 * Process this function definition.
23 * 29 *
24 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 30 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
25 * @param int $stackPtr The position of the function name in the stack. 31 * @param int $stackPtr The position of the function name in the stack.
26 * name in the stack. 32 * name in the stack.
27 * @param int $functionPtr The position of the function keyword in the stack. 33 * @param int $functionPtr The position of the function keyword in the stack.
28 * keyword in the stack. 34 * keyword in the stack.
29 * 35 *
30 * @return void 36 * @return void
31 */ 37 */
32 public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr) 38 public function processFunction(File $phpcsFile, $stackPtr, $functionPtr)
33 { 39 {
34 $fileExtension = strtolower(substr($phpcsFile->getFilename(), -7)); 40 $fileExtension = strtolower(substr($phpcsFile->getFilename(), -7));
35 // Only check in *.install files. 41 // Only check in *.install files.
36 if ($fileExtension !== 'install') { 42 if ($fileExtension !== 'install') {
37 return; 43 return;
42 if ($tokens[$stackPtr]['content'] === ($fileName.'_install') 48 if ($tokens[$stackPtr]['content'] === ($fileName.'_install')
43 || $tokens[$stackPtr]['content'] === ($fileName.'_uninstall') 49 || $tokens[$stackPtr]['content'] === ($fileName.'_uninstall')
44 ) { 50 ) {
45 // Check if there is a function body. 51 // Check if there is a function body.
46 $bodyPtr = $phpcsFile->findNext( 52 $bodyPtr = $phpcsFile->findNext(
47 PHP_CodeSniffer_Tokens::$emptyTokens, 53 Tokens::$emptyTokens,
48 ($tokens[$functionPtr]['scope_opener'] + 1), 54 ($tokens[$functionPtr]['scope_opener'] + 1),
49 $tokens[$functionPtr]['scope_closer'], 55 $tokens[$functionPtr]['scope_closer'],
50 true 56 true
51 ); 57 );
52 if ($bodyPtr === false) { 58 if ($bodyPtr === false) {