Skip to content

Commit 2dd54f0

Browse files
committed
Make InnerFunctionsSniff detect functions inside closures
1 parent ed8e00d commit 2dd54f0

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/Standards/Squiz/Sniffs/PHP/InnerFunctionsSniff.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ public function process(File $phpcsFile, $stackPtr)
4343

4444
$function = $phpcsFile->getCondition($stackPtr, T_FUNCTION);
4545
if ($function === false) {
46-
// Not a nested function.
47-
return;
46+
$function = $phpcsFile->getCondition($stackPtr, T_CLOSURE);
47+
if ($function === false) {
48+
// Not a nested function.
49+
return;
50+
}
4851
}
4952

5053
$class = $phpcsFile->getCondition($stackPtr, T_ANON_CLASS, false);

src/Standards/Squiz/Tests/PHP/InnerFunctionsUnitTest.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,10 @@ new class {
4848
}
4949
}
5050
};
51+
52+
$outerClosure = function ()
53+
{
54+
// Functions inside closures are not allowed.
55+
function innerFunction() {
56+
}
57+
};

src/Standards/Squiz/Tests/PHP/InnerFunctionsUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function getErrorList()
2828
return [
2929
5 => 1,
3030
46 => 1,
31+
55 => 1,
3132
];
3233

3334
}//end getErrorList()

0 commit comments

Comments
 (0)