1111
1212use PHP_CodeSniffer \Files \File ;
1313use PHP_CodeSniffer \Standards \Generic \Sniffs \NamingConventions \CamelCapsFunctionNameSniff ;
14- use PHP_CodeSniffer \Util \Common ;
1514
1615/**
1716 * \Drupal\Sniffs\NamingConventions\ValidFunctionNameSniff.
1817 *
1918 * Extends
2019 * \PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff
21- * to also check global function names outside the scope of classes and to not
22- * allow methods beginning with an underscore.
20+ * to also check global function names outside the scope of classes.
2321 *
2422 * @category PHP
2523 * @package PHP_CodeSniffer
@@ -39,62 +37,6 @@ class ValidFunctionNameSniff extends CamelCapsFunctionNameSniff
3937 ];
4038
4139
42- /**
43- * Processes the tokens within the scope.
44- *
45- * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed.
46- * @param int $stackPtr The position where this token was
47- * found.
48- * @param int $currScope The position of the current scope.
49- *
50- * @return void
51- */
52- protected function processTokenWithinScope (File $ phpcsFile , $ stackPtr , $ currScope )
53- {
54- $ methodName = $ phpcsFile ->getDeclarationName ($ stackPtr );
55- if ($ methodName === '' ) {
56- // Ignore closures.
57- return ;
58- }
59-
60- $ className = $ phpcsFile ->getDeclarationName ($ currScope );
61- $ errorData = [$ className . ':: ' . $ methodName ];
62-
63- // Is this a magic method. i.e., is prefixed with "__" ?
64- if (preg_match ('|^__| ' , $ methodName ) !== 0 ) {
65- $ magicPart = strtolower (substr ($ methodName , 2 ));
66- if (isset ($ this ->magicMethods [$ magicPart ]) === false
67- && isset ($ this ->methodsDoubleUnderscore [$ magicPart ]) === false
68- ) {
69- $ error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore ' ;
70- $ phpcsFile ->addError ($ error , $ stackPtr , 'MethodDoubleUnderscore ' , $ errorData );
71- }
72-
73- return ;
74- }
75-
76- $ methodProps = $ phpcsFile ->getMethodProperties ($ stackPtr );
77- if (Common::isCamelCaps ($ methodName , false , true , $ this ->strict ) === false ) {
78- if ($ methodProps ['scope_specified ' ] === true ) {
79- $ error = '%s method name "%s" is not in lowerCamel format ' ;
80- $ data = [
81- ucfirst ($ methodProps ['scope ' ]),
82- $ errorData [0 ],
83- ];
84- $ phpcsFile ->addError ($ error , $ stackPtr , 'ScopeNotCamelCaps ' , $ data );
85- } else {
86- $ error = 'Method name "%s" is not in lowerCamel format ' ;
87- $ phpcsFile ->addError ($ error , $ stackPtr , 'NotCamelCaps ' , $ errorData );
88- }
89-
90- $ phpcsFile ->recordMetric ($ stackPtr , 'CamelCase method name ' , 'no ' );
91- return ;
92- } else {
93- $ phpcsFile ->recordMetric ($ stackPtr , 'CamelCase method name ' , 'yes ' );
94- }
95- }
96-
97-
9840 /**
9941 * Processes the tokens outside the scope.
10042 *
0 commit comments