diff --git a/src/Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php b/src/Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php index ec1cfd0029..d596f17442 100644 --- a/src/Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php +++ b/src/Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php @@ -113,7 +113,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop $methodName = $phpcsFile->getDeclarationName($stackPtr); if ($methodName === null) { - // Ignore closures. + // Live coding or parse error. Bow out. return; } @@ -150,7 +150,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop return; } - // Ignore first underscore in methods prefixed with "_". + // Ignore leading underscores in the method name. $methodName = ltrim($methodName, '_'); $methodProps = $phpcsFile->getMethodProperties($stackPtr); @@ -168,7 +168,6 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop } $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no'); - return; } else { $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes'); } @@ -189,7 +188,7 @@ protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) { $functionName = $phpcsFile->getDeclarationName($stackPtr); if ($functionName === null) { - // Ignore closures. + // Live coding or parse error. Bow out. return; } @@ -206,7 +205,7 @@ protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) $phpcsFile->addError($error, $stackPtr, 'FunctionDoubleUnderscore', $errorData); } - // Ignore first underscore in functions prefixed with "_". + // Ignore leading underscores in the method name. $functionName = ltrim($functionName, '_'); if (Common::isCamelCaps($functionName, false, true, $this->strict) === false) { diff --git a/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.inc b/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.1.inc similarity index 86% rename from src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.inc rename to src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.1.inc index 8441060d27..92368d8c8d 100644 --- a/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.inc +++ b/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.1.inc @@ -183,3 +183,22 @@ enum Suit: string implements Colorful, CardGame { public function parseMyDSN() {} public function get_some_value() {} } + +interface MyInterface { + public function getSomeValue(); + public function get_some_value(); +} + +class MyClass { + // phpcs:set Generic.NamingConventions.CamelCapsFunctionName strict false + function strictFOrmatDIsabled() {} // Ok. + // phpcs:set Generic.NamingConventions.CamelCapsFunctionName strict true + + function strictFOrmatIsENabled() {} // Not ok. +} + +// phpcs:set Generic.NamingConventions.CamelCapsFunctionName strict false +function strictFOrmatDIsabled() {} // Ok. +// phpcs:set Generic.NamingConventions.CamelCapsFunctionName strict true + +function strictFOrmatIsENabled() {} // Not ok. diff --git a/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.2.inc b/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.2.inc new file mode 100644 index 0000000000..bfd1cfe25e --- /dev/null +++ b/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.2.inc @@ -0,0 +1,9 @@ + */ - public function getErrorList() + public function getErrorList($testFile='') { - $errors = [ - 10 => 1, - 11 => 1, - 12 => 1, - 13 => 1, - 16 => 1, - 17 => 1, - 20 => 1, - 21 => 1, - 24 => 1, - 25 => 1, - 30 => 1, - 31 => 1, - 50 => 1, - 52 => 1, - 53 => 2, - 57 => 1, - 58 => 1, - 59 => 1, - 60 => 1, - 61 => 1, - 62 => 1, - 63 => 1, - 64 => 1, - 65 => 1, - 66 => 1, - 67 => 1, - 68 => 2, - 69 => 1, - 71 => 1, - 72 => 1, - 73 => 2, - 118 => 1, - 144 => 1, - 146 => 1, - 147 => 2, - 158 => 1, - 159 => 1, - 179 => 1, - 180 => 2, - 183 => 1, - 184 => 1, - ]; - - return $errors; + switch ($testFile) { + case 'CamelCapsFunctionNameUnitTest.1.inc': + return[ + 10 => 1, + 11 => 1, + 12 => 1, + 13 => 1, + 16 => 1, + 17 => 1, + 20 => 1, + 21 => 1, + 24 => 1, + 25 => 1, + 30 => 1, + 31 => 1, + 50 => 1, + 52 => 1, + 53 => 2, + 57 => 1, + 58 => 1, + 59 => 1, + 60 => 1, + 61 => 1, + 62 => 1, + 63 => 1, + 64 => 1, + 65 => 1, + 66 => 1, + 67 => 1, + 68 => 2, + 69 => 1, + 71 => 1, + 72 => 1, + 73 => 2, + 118 => 1, + 144 => 1, + 146 => 1, + 147 => 2, + 158 => 1, + 159 => 1, + 179 => 1, + 180 => 2, + 183 => 1, + 184 => 1, + 189 => 1, + 197 => 1, + 204 => 1, + ]; + default: + return []; + }//end switch }//end getErrorList()