diff --git a/src/Standards/Squiz/Sniffs/PHP/EmbeddedPhpSniff.php b/src/Standards/Squiz/Sniffs/PHP/EmbeddedPhpSniff.php index 0be6118e43..63a1cdd09a 100644 --- a/src/Standards/Squiz/Sniffs/PHP/EmbeddedPhpSniff.php +++ b/src/Standards/Squiz/Sniffs/PHP/EmbeddedPhpSniff.php @@ -379,10 +379,14 @@ private function validateInlineEmbeddedPhp($phpcsFile, $stackPtr, $closeTag) } // Check that there is one, and only one space at the start of the statement. - $leadingSpace = 0; - if ($tokens[$stackPtr]['code'] === T_OPEN_TAG) { + $leadingSpace = 0; + $isLongOpenTag = false; + if ($tokens[$stackPtr]['code'] === T_OPEN_TAG + && stripos($tokens[$stackPtr]['content'], 'addFixableError($error, $stackPtr, 'SpacingAfterOpen', $data); if ($fix === true) { - if ($tokens[$stackPtr]['code'] === T_OPEN_TAG) { + if ($isLongOpenTag === true) { $phpcsFile->fixer->replaceToken(($stackPtr + 1), ''); } else if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) { // Short open tag with too much whitespace. diff --git a/src/Standards/Squiz/Tests/PHP/EmbeddedPhpUnitTest.1.inc b/src/Standards/Squiz/Tests/PHP/EmbeddedPhpUnitTest.1.inc index f28c559894..015468357d 100644 --- a/src/Standards/Squiz/Tests/PHP/EmbeddedPhpUnitTest.1.inc +++ b/src/Standards/Squiz/Tests/PHP/EmbeddedPhpUnitTest.1.inc @@ -265,6 +265,10 @@ echo 'the PHP tag is correctly indented as an indent less than the previous code echo 'the PHP tag is incorrectly indented as the indent is more than 4 different from the indent of the previous code'; ?> + + + + + + + + + + + + + + + + + + + + + + + + + + 1, 263 => 1, 264 => 1, + 270 => 1, ]; case 'EmbeddedPhpUnitTest.2.inc': @@ -190,6 +191,16 @@ public function getErrorList($testFile='') 22 => 2, ]; + case 'EmbeddedPhpUnitTest.24.inc': + $shortOpenTagDirective = (bool) ini_get('short_open_tag'); + if ($shortOpenTagDirective === true) { + return [ + 18 => 1, + 20 => 1, + ]; + } + return []; + default: return []; }//end switch