Skip to content

Commit cb574ff

Browse files
committed
Simplify two regexes by removing unnecessary \?-> and ensure related tests follow WP coding standards
1 parent bf36d36 commit cb574ff

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

WordPress/Sniffs/WP/AlternativeFunctionsSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content
283283
}
284284

285285
$contains_wp_path_constant = preg_match(
286-
'`(?<!\?->|->|::)\b(?:ABSPATH|WP_(?:CONTENT|PLUGIN)_DIR|WPMU_PLUGIN_DIR|TEMPLATEPATH|STYLESHEETPATH|(?:MU)?PLUGINDIR)\b`',
286+
'`(?<!->|::)\b(?:ABSPATH|WP_(?:CONTENT|PLUGIN)_DIR|WPMU_PLUGIN_DIR|TEMPLATEPATH|STYLESHEETPATH|(?:MU)?PLUGINDIR)\b`',
287287
$filename_param['clean']
288288
);
289289
if ( 1 === $contains_wp_path_constant ) {
@@ -292,7 +292,7 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content
292292
}
293293

294294
$contains_wp_path_function_call = preg_match(
295-
'`(?<!\?->|->|::)(?:get_home_path|plugin_dir_path|get_(?:stylesheet|template)_directory|wp_upload_dir)\s*\(`i',
295+
'`(?<!->|::)(?:get_home_path|plugin_dir_path|get_(?:stylesheet|template)_directory|wp_upload_dir)\s*\(`i',
296296
$filename_param['clean']
297297
);
298298
if ( 1 === $contains_wp_path_function_call ) {

WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ namespace\Sub\strip_tags( $string );
161161
* Safeguard that the sniff does not incorrectly ignore class methods/constants with the same
162162
* name as WordPress global functions/constants when used in file_get_contents().
163163
*/
164-
file_get_contents(MyClass::wp_upload_dir() . 'subdir/file.inc');
165-
file_get_contents($this->GET_HOME_PATH() . 'subdir/file.inc');
166-
file_get_contents($this?->plugin_dir_path() . 'subdir/file.inc');
167-
file_get_contents(MyClass::ABSPATH . 'subdir/file.inc');
168-
file_get_contents($this->WPMU_PLUGIN_DIR . 'subdir/file.inc');
169-
file_get_contents($this?->TEMPLATEPATH . 'subdir/file.inc');
164+
file_get_contents( MyClass::wp_upload_dir() . 'subdir/file.inc' );
165+
file_get_contents( $this->GET_HOME_PATH() . 'subdir/file.inc' );
166+
file_get_contents( $this?->plugin_dir_path() . 'subdir/file.inc' );
167+
file_get_contents( MyClass::ABSPATH . 'subdir/file.inc' );
168+
file_get_contents( $this->WPMU_PLUGIN_DIR . 'subdir/file.inc' );
169+
file_get_contents( $this?->TEMPLATEPATH . 'subdir/file.inc' );

0 commit comments

Comments
 (0)