Skip to content

Commit ae8557a

Browse files
committed
Performance/TaxonomyMetaInOptions: add support for handling PHP 8.0+ nullsafe object operator
Includes test.
1 parent 1f24aad commit ae8557a

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

WordPressVIPMinimum/Sniffs/Performance/TaxonomyMetaInOptionsSniff.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
117117
}
118118

119119
$object_operator = $this->phpcsFile->findNext( Tokens::$emptyTokens, $variable_name + 1, null, true );
120-
if ( $this->tokens[ $object_operator ]['code'] !== T_OBJECT_OPERATOR ) {
120+
if ( $this->tokens[ $object_operator ]['code'] !== T_OBJECT_OPERATOR
121+
&& $this->tokens[ $object_operator ]['code'] !== T_NULLSAFE_OBJECT_OPERATOR
122+
) {
121123
return;
122124
}
123125

WordPressVIPMinimum/Tests/Performance/TaxonomyMetaInOptionsUnitTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ add_option(value: "$tag_id", option: 'option_name'); // OK.
6161
update_option(autoload: true, optin: "$tag_id", value: 10,); // OK, well, not really, typo in param name, but that's not the concern of the sniff.
6262

6363
add_option(value: $value, option: "$tag_id" ); // Bad.
64+
65+
// Safeguard handling of PHP 8.0+ nullsafe object operator.
66+
get_option( 'taxonomy_rating_' . $obj?->term_id ); // NOK.

WordPressVIPMinimum/Tests/Performance/TaxonomyMetaInOptionsUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function getWarningList() {
3939
54 => 1,
4040
55 => 1,
4141
63 => 1,
42+
66 => 1,
4243
];
4344
}
4445
}

0 commit comments

Comments
 (0)