Skip to content

Commit 352a8b3

Browse files
committed
ControlStructureSpacing: fix undefined index error
Closure `use` parentheses do not have a parenthesis owner. While this is a plaster on the wound as the sniff really needs to be split up, for now, it fixes the notice. Fixes 1792
1 parent d45f5e5 commit 352a8b3

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ public function process_token( $stackPtr ) {
346346
if ( \T_WHITESPACE !== $this->tokens[ ( $parenthesisCloser + 1 ) ]['code']
347347
&& ! ( // Do NOT flag : immediately following ) for return types declarations.
348348
\T_COLON === $this->tokens[ ( $parenthesisCloser + 1 ) ]['code']
349-
&& in_array( $this->tokens[ $this->tokens[ $parenthesisCloser ]['parenthesis_owner'] ]['code'], array( \T_FUNCTION, \T_CLOSURE ), true )
349+
&& ( isset( $this->tokens[ $parenthesisCloser ]['parenthesis_owner'] ) === false
350+
|| in_array( $this->tokens[ $this->tokens[ $parenthesisCloser ]['parenthesis_owner'] ]['code'], array( \T_FUNCTION, \T_CLOSURE ), true ) )
350351
)
351352
&& ( isset( $scopeOpener ) && \T_COLON !== $this->tokens[ $scopeOpener ]['code'] )
352353
) {

WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,18 @@ $returntype = function ( string $input ): string {}; // Ok.
290290
$returntype = function ( string $input ) : string {}; // Ok.
291291
$returntype = function ( string $input, array $inputs ): string {}; // Ok.
292292
$returntype = function ( string $input, array $inputs ) : string {}; // Ok.
293+
294+
// Issue 1792.
295+
$matching_options = array_filter(
296+
$imported_options,
297+
function ( $option ) use ( $option_id ): bool {
298+
return $option['id'] === $option_id;
299+
}
300+
);
301+
302+
$matching_options = array_filter(
303+
$imported_options,
304+
function ( $option ) use ( $option_id ) : bool {
305+
return $option['id'] === $option_id;
306+
}
307+
);

WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,18 @@ $returntype = function ( string $input ): string {}; // Ok.
279279
$returntype = function ( string $input ) : string {}; // Ok.
280280
$returntype = function ( string $input, array $inputs ): string {}; // Ok.
281281
$returntype = function ( string $input, array $inputs ) : string {}; // Ok.
282+
283+
// Issue 1792.
284+
$matching_options = array_filter(
285+
$imported_options,
286+
function ( $option ) use ( $option_id ): bool {
287+
return $option['id'] === $option_id;
288+
}
289+
);
290+
291+
$matching_options = array_filter(
292+
$imported_options,
293+
function ( $option ) use ( $option_id ) : bool {
294+
return $option['id'] === $option_id;
295+
}
296+
);

0 commit comments

Comments
 (0)