Skip to content

Commit

Permalink
Merge pull request #1837 from WordPress/feature/1792-controlstructure…
Browse files Browse the repository at this point in the history
…spacing-closure-use-return-type

ControlStructureSpacing: fix undefined index error
  • Loading branch information
dingo-d committed Dec 6, 2019
2 parents eea3371 + 352a8b3 commit 370ae76
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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;
}
);

0 comments on commit 370ae76

Please sign in to comment.