Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ControlStructureSpacing: fix undefined index error #1837

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ public function process_token( $stackPtr ) {
if ( \T_WHITESPACE !== $this->tokens[ ( $parenthesisCloser + 1 ) ]['code']
&& ! ( // Do NOT flag : immediately following ) for return types declarations.
\T_COLON === $this->tokens[ ( $parenthesisCloser + 1 ) ]['code']
&& in_array( $this->tokens[ $this->tokens[ $parenthesisCloser ]['parenthesis_owner'] ]['code'], array( \T_FUNCTION, \T_CLOSURE ), true )
&& ( isset( $this->tokens[ $parenthesisCloser ]['parenthesis_owner'] ) === false
|| in_array( $this->tokens[ $this->tokens[ $parenthesisCloser ]['parenthesis_owner'] ]['code'], array( \T_FUNCTION, \T_CLOSURE ), true ) )
)
&& ( isset( $scopeOpener ) && \T_COLON !== $this->tokens[ $scopeOpener ]['code'] )
) {
Expand Down
15 changes: 15 additions & 0 deletions WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,18 @@ $returntype = function ( string $input ): string {}; // Ok.
$returntype = function ( string $input ) : string {}; // Ok.
$returntype = function ( string $input, array $inputs ): string {}; // Ok.
$returntype = function ( string $input, array $inputs ) : string {}; // Ok.

// Issue 1792.
$matching_options = array_filter(
$imported_options,
function ( $option ) use ( $option_id ): bool {
return $option['id'] === $option_id;
}
);

$matching_options = array_filter(
$imported_options,
function ( $option ) use ( $option_id ) : bool {
return $option['id'] === $option_id;
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,18 @@ $returntype = function ( string $input ): string {}; // Ok.
$returntype = function ( string $input ) : string {}; // Ok.
$returntype = function ( string $input, array $inputs ): string {}; // Ok.
$returntype = function ( string $input, array $inputs ) : string {}; // Ok.

// Issue 1792.
$matching_options = array_filter(
$imported_options,
function ( $option ) use ( $option_id ): bool {
return $option['id'] === $option_id;
}
);

$matching_options = array_filter(
$imported_options,
function ( $option ) use ( $option_id ) : bool {
return $option['id'] === $option_id;
}
);