comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Scope/MethodScopeSniff.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
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 9
10 namespace Drupal\Sniffs\Scope;
11
12 use PHP_CodeSniffer\Files\File;
13 use PHP_CodeSniffer\Sniffs\AbstractScopeSniff;
14 use PHP_CodeSniffer\Util\Tokens;
15
10 /** 16 /**
11 * Verifies that class/interface/trait methods have scope modifiers. 17 * Verifies that class/interface/trait methods have scope modifiers.
12 * 18 *
13 * Laregely copied from Squiz_Sniffs_Scope_MethodScopeSniff to work on traits 19 * Laregely copied from
14 * and have a fixer. 20 * \PHP_CodeSniffer\Standards\Squiz\Sniffs\Scope\MethodScopeSniff to work on
21 * traits and have a fixer.
15 * 22 *
16 * @category PHP 23 * @category PHP
17 * @package PHP_CodeSniffer 24 * @package PHP_CodeSniffer
18 * @link http://pear.php.net/package/PHP_CodeSniffer 25 * @link http://pear.php.net/package/PHP_CodeSniffer
19 */ 26 */
20 class Drupal_Sniffs_Scope_MethodScopeSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff 27 class MethodScopeSniff extends AbstractScopeSniff
21 { 28 {
22 29
23 30
24 /** 31 /**
25 * Constructs a Squiz_Sniffs_Scope_MethodScopeSniff. 32 * Constructs a
33 * \PHP_CodeSniffer\Standards\Squiz\Sniffs\Scope\MethodScopeSniff.
26 */ 34 */
27 public function __construct() 35 public function __construct()
28 { 36 {
29 parent::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION)); 37 parent::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION));
30 38
32 40
33 41
34 /** 42 /**
35 * Processes the function tokens within the class. 43 * Processes the function tokens within the class.
36 * 44 *
37 * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. 45 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
38 * @param int $stackPtr The position where the token was found. 46 * @param int $stackPtr The position where the token was found.
39 * @param int $currScope The current scope opener token. 47 * @param int $currScope The current scope opener token.
40 * 48 *
41 * @return void 49 * @return void
42 */ 50 */
43 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) 51 protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
44 { 52 {
45 $tokens = $phpcsFile->getTokens(); 53 $tokens = $phpcsFile->getTokens();
46 54
47 $methodName = $phpcsFile->getDeclarationName($stackPtr); 55 $methodName = $phpcsFile->getDeclarationName($stackPtr);
48 if ($methodName === null) { 56 if ($methodName === null) {
57 65
58 $modifier = null; 66 $modifier = null;
59 for ($i = ($stackPtr - 1); $i > 0; $i--) { 67 for ($i = ($stackPtr - 1); $i > 0; $i--) {
60 if ($tokens[$i]['line'] < $tokens[$stackPtr]['line']) { 68 if ($tokens[$i]['line'] < $tokens[$stackPtr]['line']) {
61 break; 69 break;
62 } else if (isset(PHP_CodeSniffer_Tokens::$scopeModifiers[$tokens[$i]['code']]) === true) { 70 } else if (isset(Tokens::$scopeModifiers[$tokens[$i]['code']]) === true) {
63 $modifier = $i; 71 $modifier = $i;
64 break; 72 break;
65 } 73 }
66 } 74 }
67 75
78 } 86 }
79 87
80 }//end processTokenWithinScope() 88 }//end processTokenWithinScope()
81 89
82 90
91 /**
92 * Processes a token that is found outside the scope that this test is
93 * listening to.
94 *
95 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
96 * @param int $stackPtr The position in the stack where this
97 * token was found.
98 *
99 * @return void
100 */
101 protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
102 {
103
104 }//end processTokenOutsideScope()
105
106
83 }//end class 107 }//end class