Skip to content
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
11 changes: 9 additions & 2 deletions WordPressVIPMinimum/Sniffs/Hooks/AlwaysReturnInFilterSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public function process_token( $stackPtr ) {

if ( 'PHPCS_T_CLOSURE' === $this->tokens[ $callbackPtr ]['code'] ) {
$this->processFunctionBody( $callbackPtr );
} elseif ( 'T_ARRAY' === $this->tokens[ $callbackPtr ]['type'] ) {
} elseif ( T_ARRAY === $this->tokens[ $callbackPtr ]['code']
|| T_OPEN_SHORT_ARRAY === $this->tokens[ $callbackPtr ]['code']
) {
$this->processArray( $callbackPtr );
} elseif ( true === in_array( $this->tokens[ $callbackPtr ]['code'], Tokens::$stringTokens, true ) ) {
$this->processString( $callbackPtr );
Expand All @@ -92,9 +94,14 @@ public function process_token( $stackPtr ) {
*/
private function processArray( $stackPtr ) {

$open_close = $this->find_array_open_close( $stackPtr );
if ( false === $open_close ) {
return;
}

$previous = $this->phpcsFile->findPrevious(
Tokens::$emptyTokens,
$this->tokens[ $stackPtr ]['parenthesis_closer'] - 1,
$open_close['closer'] - 1,
null,
true
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,38 @@ function bad_example_arg( $test ) { // Error.
// Missing universal return.
}
add_filter( 'bad_example_filter', 'bad_example_arg' );

class good_example_class_short_array { // Ok.
public function __construct() {
add_filter( 'good_example_class_filter', [ $this, 'class_filter' ] );
}

public function class_filter( $param ) {
if ( 1 === 1 ) {
if ( 1 === 0 ) {
return 'whoops';
} else {
return 'here!';
}
}
return 'This is Okay';
}
}

class bad_example_class_short_array { // Error.
public function __construct() {
add_filter( 'bad_example_class_filter', [ $this, 'class_filter' ] );
}

public function class_filter( $param ) {
if ( 1 === 1 ) {
if ( 1 === 0 ) {
return 'whoops';
} else {
return 'here!';
}
}
// Missing universal return.
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function getErrorList() {
95 => 1,
105 => 1,
129 => 1,
163 => 1,
];
}

Expand Down