@@ -823,6 +823,59 @@ protected function tokenize($string)
823823 continue ;
824824 }//end if
825825
826+ /*
827+ Split whitespace off from long PHP open tag tokens and potentially join the whitespace
828+ with a subsequent whitespace token.
829+ */
830+
831+ if ($ tokenIsArray === true
832+ && $ token [0 ] === T_OPEN_TAG
833+ && stripos ($ token [1 ], '<?php ' ) === 0
834+ ) {
835+ $ openTagAndWhiteSpace = str_split ($ token [1 ], 5 );
836+
837+ $ finalTokens [$ newStackPtr ] = [
838+ 'code ' => T_OPEN_TAG ,
839+ 'type ' => 'T_OPEN_TAG ' ,
840+ 'content ' => $ openTagAndWhiteSpace [0 ],
841+ ];
842+ $ newStackPtr ++;
843+
844+ if (isset ($ openTagAndWhiteSpace [1 ]) === true ) {
845+ // The original open tag token included whitespace.
846+ // Check whether a new whitespace token needs to be inserted or if the
847+ // whitespace needs to be joined with a pre-existing whitespace
848+ // token on the same line as the open tag.
849+ if (isset ($ tokens [($ stackPtr + 1 )]) === true
850+ && $ openTagAndWhiteSpace [1 ] === ' '
851+ && is_array ($ tokens [($ stackPtr + 1 )]) === true
852+ && $ tokens [($ stackPtr + 1 )][0 ] === T_WHITESPACE
853+ ) {
854+ // Adjusting the original token stack as the "new line may be split over two tokens"
855+ // check should still be run on this token.
856+ $ tokens [($ stackPtr + 1 )][1 ] = $ openTagAndWhiteSpace [1 ].$ tokens [($ stackPtr + 1 )][1 ];
857+
858+ if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
859+ StatusWriter::write ("* removed whitespace from T_OPEN_TAG token $ stackPtr and merged it with the next token T_WHITESPACE " , 2 );
860+ }
861+ } else {
862+ $ finalTokens [$ newStackPtr ] = [
863+ 'code ' => T_WHITESPACE ,
864+ 'type ' => 'T_WHITESPACE ' ,
865+ 'content ' => $ openTagAndWhiteSpace [1 ],
866+ ];
867+
868+ if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
869+ StatusWriter::write ("* T_OPEN_TAG token $ stackPtr split into T_OPEN_TAG (without whitespace) and new T_WHITESPACE token " , 2 );
870+ }
871+
872+ $ newStackPtr ++;
873+ }//end if
874+ }//end if
875+
876+ continue ;
877+ }//end if
878+
826879 /*
827880 Parse doc blocks into something that can be easily iterated over.
828881 */
0 commit comments