diff --git a/src/Tokenizer/Tokens.php b/src/Tokenizer/Tokens.php index 15044fef033..edb321167f5 100644 --- a/src/Tokenizer/Tokens.php +++ b/src/Tokenizer/Tokens.php @@ -1088,17 +1088,19 @@ public function clearRange(int $indexStart, int $indexEnd): void */ public function isMonolithicPhp(): bool { - $size = $this->count(); - - if (0 === $size) { + if (0 === $this->count()) { return false; } - if ($this->isTokenKindFound(T_INLINE_HTML)) { + if ($this->countTokenKind(T_INLINE_HTML) > 1) { return false; } - return 1 >= ($this->countTokenKind(T_OPEN_TAG) + $this->countTokenKind(T_OPEN_TAG_WITH_ECHO)); + if (1 === $this->countTokenKind(T_INLINE_HTML)) { + return 1 === Preg::match('/^#!.+$/', $this[0]->getContent()); + } + + return 1 === ($this->countTokenKind(T_OPEN_TAG) + $this->countTokenKind(T_OPEN_TAG_WITH_ECHO)); } /** diff --git a/tests/Tokenizer/TokensTest.php b/tests/Tokenizer/TokensTest.php index 458c448ac98..202a9220b00 100644 --- a/tests/Tokenizer/TokensTest.php +++ b/tests/Tokenizer/TokensTest.php @@ -353,12 +353,26 @@ public function provideMonolithicPhpDetectionCases(): iterable { yield [true, ""]; + yield [false, "#!\n "]; yield [false, "']; + yield [false, ' World!']; // short open tag yield [(bool) ini_get('short_open_tag'), ""];