Mercurial > hg > isophonics-drupal-site
comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.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_NamingConventions_ValidFunctionNameSniff. | 3 * \Drupal\Sniffs\NamingConventions\ValidFunctionNameSniff. |
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 | 9 |
10 namespace Drupal\Sniffs\NamingConventions; | |
11 | |
12 use PHP_CodeSniffer\Files\File; | |
13 use PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff; | |
14 use PHP_CodeSniffer\Util\Common; | |
15 | |
10 /** | 16 /** |
11 * Drupal_Sniffs_NamingConventions_ValidFunctionNameSniff. | 17 * \Drupal\Sniffs\NamingConventions\ValidFunctionNameSniff. |
12 * | 18 * |
13 * Extends Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff to also check | 19 * Extends |
14 * global function names outside the scope of classes and to not allow methods | 20 * \PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff |
15 * beginning with an underscore. | 21 * to also check global function names outside the scope of classes and to not |
22 * allow methods beginning with an underscore. | |
16 * | 23 * |
17 * @category PHP | 24 * @category PHP |
18 * @package PHP_CodeSniffer | 25 * @package PHP_CodeSniffer |
19 * @link http://pear.php.net/package/PHP_CodeSniffer | 26 * @link http://pear.php.net/package/PHP_CodeSniffer |
20 */ | 27 */ |
21 class Drupal_Sniffs_NamingConventions_ValidFunctionNameSniff extends Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff | 28 class ValidFunctionNameSniff extends CamelCapsFunctionNameSniff |
22 { | 29 { |
23 | 30 |
24 | 31 |
25 /** | 32 /** |
26 * Processes the tokens within the scope. | 33 * Processes the tokens within the scope. |
27 * | 34 * |
28 * @param PHP_CodeSniffer_File $phpcsFile The file being processed. | 35 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed. |
29 * @param int $stackPtr The position where this token was | 36 * @param int $stackPtr The position where this token was |
30 * found. | 37 * found. |
31 * @param int $currScope The position of the current scope. | 38 * @param int $currScope The position of the current scope. |
32 * | 39 * |
33 * @return void | 40 * @return void |
34 */ | 41 */ |
35 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) | 42 protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) |
36 { | 43 { |
37 $methodName = $phpcsFile->getDeclarationName($stackPtr); | 44 $methodName = $phpcsFile->getDeclarationName($stackPtr); |
38 if ($methodName === null) { | 45 if ($methodName === null) { |
39 // Ignore closures. | 46 // Ignore closures. |
40 return; | 47 return; |
55 | 62 |
56 return; | 63 return; |
57 } | 64 } |
58 | 65 |
59 $methodProps = $phpcsFile->getMethodProperties($stackPtr); | 66 $methodProps = $phpcsFile->getMethodProperties($stackPtr); |
60 if (PHP_CodeSniffer::isCamelCaps($methodName, false, true, $this->strict) === false) { | 67 if (Common::isCamelCaps($methodName, false, true, $this->strict) === false) { |
61 if ($methodProps['scope_specified'] === true) { | 68 if ($methodProps['scope_specified'] === true) { |
62 $error = '%s method name "%s" is not in lowerCamel format'; | 69 $error = '%s method name "%s" is not in lowerCamel format'; |
63 $data = array( | 70 $data = array( |
64 ucfirst($methodProps['scope']), | 71 ucfirst($methodProps['scope']), |
65 $errorData[0], | 72 $errorData[0], |
80 | 87 |
81 | 88 |
82 /** | 89 /** |
83 * Processes the tokens outside the scope. | 90 * Processes the tokens outside the scope. |
84 * | 91 * |
85 * @param PHP_CodeSniffer_File $phpcsFile The file being processed. | 92 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed. |
86 * @param int $stackPtr The position where this token was | 93 * @param int $stackPtr The position where this token was |
87 * found. | 94 * found. |
88 * | 95 * |
89 * @return void | 96 * @return void |
90 */ | 97 */ |
91 protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | 98 protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) |
92 { | 99 { |
93 $functionName = $phpcsFile->getDeclarationName($stackPtr); | 100 $functionName = $phpcsFile->getDeclarationName($stackPtr); |
94 if ($functionName === null) { | 101 if ($functionName === null) { |
95 // Ignore closures. | 102 // Ignore closures. |
96 return; | 103 return; |