Skip to content
Browse files

Allow anonymous functions. Fixes #3614

  • Loading branch information...
1 parent 28f647d commit fbf83afad51cfd3f636a91a3a64bb18657931358 @cbandy cbandy committed
View
8 PHP/CodeSniffer/Standards/Kohana/Sniffs/NamingConventions/ValidFunctionNameSniff.php
@@ -86,6 +86,10 @@ protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $sta
$className = $phpcsFile->getDeclarationName($currScope);
$methodName = $phpcsFile->getDeclarationName($stackPtr);
+ // Ignore anonymous functions used within a class
+ if ( ! $methodName)
+ return;
+
// Ignore magic methods
if (substr($methodName, 0, 2) == '__') {
$magicPart = substr($methodName, 2);
@@ -119,6 +123,10 @@ protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $st
{
$functionName = $phpcsFile->getDeclarationName($stackPtr);
+ // Ignore anonymous functions
+ if ( ! $functionName)
+ return;
+
// Ignore magic functions
if (substr($functionName, 0, 2) == '__') {
if (in_array(substr($functionName, 2), $this->_magicFunctions) === false) {
View
9 ...niffer/CodeSniffer/Standards/Kohana/Tests/NamingConventions/ValidFunctionNameUnitTest.inc
@@ -169,4 +169,13 @@ function my_package_function() {}
function Package_() {}
function Package() {}
+function () {}
+
+class Closure_Test {
+ function closure()
+ {
+ return function () {};
+ }
+}
+
?>

0 comments on commit fbf83af

Please sign in to comment.
Something went wrong with that request. Please try again.