Skip to content

Commit 3d43f2f

Browse files
committed
Allow static closure for hooks
See #29
1 parent 8defbc0 commit 3d43f2f

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

Inpsyde/PhpcsHelpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public static function isHookClosure(
330330
}
331331

332332
$lookForComma = $file->findPrevious(
333-
[T_WHITESPACE],
333+
[T_WHITESPACE, T_STATIC],
334334
$closurePosition - 1,
335335
null,
336336
true,

tests/fixtures/argument-type-declaration.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ function ($foo) {
6060
}
6161
);
6262

63+
add_filter(
64+
'foo',
65+
static function ($foo) {
66+
return true;
67+
}
68+
);
69+
6370
array_map(
6471
function ($foo) { // @phpcsWarningOnThisLine
6572

@@ -173,15 +180,31 @@ function (PHPUnit\Exception $meh = null) use ($baz)
173180
class ArgumentTypeDeclarationSniffTestFixture
174181
{
175182
// @phpcsWarningOnNextLine
176-
function a($bar)
183+
public function a($bar)
177184
{
178185
function (array $baz) use ($bar)
179186
{
180187

181188
}
182189
}
183190

184-
function b(array $bar)
191+
// @phpcsWarningOnNextLine
192+
private function ap($bar)
193+
{
194+
function (array $baz) use ($bar)
195+
{
196+
197+
}
198+
}
199+
200+
/**
201+
* @wp-hook foo
202+
*/
203+
private function theHook($param)
204+
{
205+
}
206+
207+
protected function b(array $bar)
185208
{
186209
function (array $baz) use ($bar)
187210
{
@@ -193,7 +216,7 @@ function ($meh) use ($baz)
193216
}
194217
}
195218

196-
function c(array $bar)
219+
private function c(array $bar)
197220
{
198221

199222
function (array $baz) use ($bar)

tests/fixtures/return-type-declaration.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ function genMultiReturn(): \Generator
184184
return '';
185185
});
186186

187+
add_filter('x', static function () {
188+
return '';
189+
});
190+
187191
// @phpcsErrorCodeOnNextLine IncorrectVoidReturnType
188192
add_filter('x', function (): void {
189193
return '0';
@@ -243,7 +247,7 @@ function noHookCallback() // @phpcsWarningCodeOnThisLine NoReturnType
243247
class WrapperHookWrapper
244248
{
245249

246-
function filterWrapper(string $x, int $y): bool
250+
public function filterWrapper(string $x, int $y): bool
247251
{
248252

249253
// @phpcsWarningCodeOnNextLine NoReturnType
@@ -275,7 +279,7 @@ function ($x, $y) {
275279
}
276280

277281
// @phpcsWarningCodeOnNextLine NoReturnType
278-
function problematicMethod()
282+
protected function problematicMethod()
279283
{
280284
return 'x';
281285
}
@@ -284,13 +288,13 @@ function problematicMethod()
284288
* @return string
285289
* @wp-hook Meh
286290
*/
287-
function hookMethod()
291+
private function hookMethod()
288292
{
289293
return 'x';
290294
}
291295

292296
// @phpcsErrorCodeOnNextLine IncorrectVoidReturn
293-
function problematicMethodTwo(): bool
297+
protected function problematicMethodTwo(): bool
294298
{
295299
if (true) {
296300
return true;

0 commit comments

Comments
 (0)