Skip to content

Commit b82bc3e

Browse files
authored
Merge pull request #1848 from JPry/bug/issue_1847
Fix off-by-one error when $treat_files_as_scoped is true
2 parents 52d0047 + 9525f51 commit b82bc3e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ protected function process_global_statement( $stackPtr, $in_function_scope ) {
351351
$end = $this->tokens[ $scope_cond ]['scope_closer'];
352352
} else {
353353
// Global statement in the global namespace with file is being treated as scoped.
354-
$end = ( $this->phpcsFile->numTokens + 1 );
354+
$end = $this->phpcsFile->numTokens;
355355
}
356356

357357
for ( $ptr = $start; $ptr < $end; $ptr++ ) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// phpcs:set WordPress.WP.GlobalVariablesOverride treat_files_as_scoped true
4+
5+
global $post;
6+
7+
// phpcs:set WordPress.WP.GlobalVariablesOverride treat_files_as_scoped false

0 commit comments

Comments
 (0)