diff --git a/Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php b/Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php index 5ce7c20d..c0e6ce46 100644 --- a/Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php +++ b/Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php @@ -68,17 +68,16 @@ public function register(): array * * @param File $phpcsFile * @param int $stackPtr - * @return void + * + * @return int */ - public function process(File $phpcsFile, $stackPtr): void + public function process(File $phpcsFile, $stackPtr): int { - if ($stackPtr !== 0) { - return; - } - $html = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens())); + $tokenCount = count($phpcsFile->getTokens()); + $html = $phpcsFile->getTokensAsString($stackPtr, $tokenCount - $stackPtr); if (empty($html)) { - return; + return $tokenCount + 1; } if (preg_match_all('$<(\w{2,})\s?[^<]*\/>$', $html, $matches, PREG_SET_ORDER)) { @@ -92,5 +91,7 @@ public function process(File $phpcsFile, $stackPtr): void } } } + + return $tokenCount + 1; } } diff --git a/Magento2/Sniffs/Html/HtmlCollapsibleAttributeSniff.php b/Magento2/Sniffs/Html/HtmlCollapsibleAttributeSniff.php index 8798c416..c5a5672a 100644 --- a/Magento2/Sniffs/Html/HtmlCollapsibleAttributeSniff.php +++ b/Magento2/Sniffs/Html/HtmlCollapsibleAttributeSniff.php @@ -29,17 +29,16 @@ public function register() * * @param File $phpcsFile * @param int $stackPtr - * @return int|void + * + * @return int */ - public function process(File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr): int { - if ($stackPtr !== 0) { - return; - } - $html = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens())); + $tokenCount = count($phpcsFile->getTokens()); + $html = $phpcsFile->getTokensAsString($stackPtr, $tokenCount - $stackPtr); if (empty($html)) { - return; + return $tokenCount + 1; } $pattern = '$<\w+.*?\s*(?=.*?\s*data-toggle="collapse")[^>]*?>.*?$'; @@ -54,5 +53,7 @@ public function process(File $phpcsFile, $stackPtr) ); } } + + return $tokenCount + 1; } } diff --git a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php index 2fdc0518..e8589440 100644 --- a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php +++ b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php @@ -44,20 +44,19 @@ public function register() * * @param File $phpcsFile * @param int $stackPtr - * @return int|void + * + * @return int */ - public function process(File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr): int { $this->usedVariables = []; $this->unfilteredVariables = []; - if ($stackPtr !== 0) { - return; - } - $html = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens())); + $tokenCount = count($phpcsFile->getTokens()); + $html = $phpcsFile->getTokensAsString($stackPtr, $tokenCount - $stackPtr); if (empty($html)) { - return; + return $tokenCount + 1; } $html = $this->processIfDirectives($html, $phpcsFile); @@ -66,6 +65,8 @@ public function process(File $phpcsFile, $stackPtr) $html = $this->processVarDirectivesAndParams($html, $phpcsFile); $this->validateDefinedVariables($phpcsFile, $html); + + return $tokenCount + 1; } /** diff --git a/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php b/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php index ecbdca44..c647f48c 100644 --- a/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php +++ b/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php @@ -55,17 +55,16 @@ public function register() * * @param File $phpcsFile * @param int $stackPtr - * @return int|void + * + * @return int */ - public function process(File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr): int { - if ($stackPtr !== 0) { - return; - } - $html = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens())); + $tokenCount = count($phpcsFile->getTokens()); + $html = $phpcsFile->getTokensAsString($stackPtr, $tokenCount - $stackPtr); if (empty($html)) { - return; + return $tokenCount + 1; } if (preg_match_all('$<(\w{2,})\s?[^<]*\/>$', $html, $matches, PREG_SET_ORDER)) { @@ -80,5 +79,7 @@ public function process(File $phpcsFile, $stackPtr) } } } + + return $tokenCount + 1; } } diff --git a/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc b/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.1.inc similarity index 100% rename from Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc rename to Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.1.inc diff --git a/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.2.inc b/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.2.inc new file mode 100644 index 00000000..336c75a1 --- /dev/null +++ b/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.2.inc @@ -0,0 +1,35 @@ + + + + + + + + + +
+ + + + +
+ +
+ + + + + + + + + + diff --git a/Magento2/Tests/Html/HtmlCollapsibleAttributeUnitTest.2.inc b/Magento2/Tests/Html/HtmlCollapsibleAttributeUnitTest.2.inc new file mode 100644 index 00000000..6551f9ff --- /dev/null +++ b/Magento2/Tests/Html/HtmlCollapsibleAttributeUnitTest.2.inc @@ -0,0 +1,35 @@ + + + + + + + + +
+ +
+
+ + + +
+
+ Test +
+ > + escapeHtml($element->getLegend()) ?> + + + diff --git a/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.2.inc b/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.2.inc new file mode 100644 index 00000000..70d92444 --- /dev/null +++ b/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.2.inc @@ -0,0 +1,45 @@ + + + + + + + + + +
+ + + + +
+ +
+ + + + + + + + + +