diff --git a/src/Generators/HTML.php b/src/Generators/HTML.php
index b7e209f46a..5290280b75 100644
--- a/src/Generators/HTML.php
+++ b/src/Generators/HTML.php
@@ -410,16 +410,29 @@ protected function getFormattedCodeComparisonBlock(DOMNode $node)
$second = str_replace('', '', $second);
$second = str_replace('', '', $second);
- $output = '
'.PHP_EOL;
- $output .= ' '.PHP_EOL;
- $output .= " | $firstTitle | ".PHP_EOL;
- $output .= " $secondTitle | ".PHP_EOL;
- $output .= '
'.PHP_EOL;
- $output .= ' '.PHP_EOL;
- $output .= " | $first | ".PHP_EOL;
- $output .= " $second | ".PHP_EOL;
- $output .= '
'.PHP_EOL;
- $output .= '
'.PHP_EOL;
+ $titleRow = '';
+ if ($firstTitle !== '' || $secondTitle !== '') {
+ $titleRow .= ' '.PHP_EOL;
+ $titleRow .= " | $firstTitle | ".PHP_EOL;
+ $titleRow .= " $secondTitle | ".PHP_EOL;
+ $titleRow .= '
'.PHP_EOL;
+ }
+
+ $codeRow = '';
+ if ($first !== '' || $second !== '') {
+ $codeRow .= ' '.PHP_EOL;
+ $codeRow .= " | $first | ".PHP_EOL;
+ $codeRow .= " $second | ".PHP_EOL;
+ $codeRow .= '
'.PHP_EOL;
+ }
+
+ $output = '';
+ if ($titleRow !== '' || $codeRow !== '') {
+ $output = ' '.PHP_EOL;
+ $output .= $titleRow;
+ $output .= $codeRow;
+ $output .= '
'.PHP_EOL;
+ }
return $output;
diff --git a/src/Generators/Markdown.php b/src/Generators/Markdown.php
index d03d06a115..0fb40a4e29 100644
--- a/src/Generators/Markdown.php
+++ b/src/Generators/Markdown.php
@@ -264,20 +264,33 @@ protected function getFormattedCodeComparisonBlock(DOMNode $node)
$second = str_replace('', '', $second);
$second = str_replace('', '', $second);
- $output = ' '.PHP_EOL;
- $output .= ' '.PHP_EOL;
- $output .= " | $firstTitle | ".PHP_EOL;
- $output .= " $secondTitle | ".PHP_EOL;
- $output .= '
'.PHP_EOL;
- $output .= ' '.PHP_EOL;
- $output .= '| '.PHP_EOL.PHP_EOL;
- $output .= " $first".PHP_EOL.PHP_EOL;
- $output .= ' | '.PHP_EOL;
- $output .= ''.PHP_EOL.PHP_EOL;
- $output .= " $second".PHP_EOL.PHP_EOL;
- $output .= ' | '.PHP_EOL;
- $output .= '
'.PHP_EOL;
- $output .= '
'.PHP_EOL;
+ $titleRow = '';
+ if ($firstTitle !== '' || $secondTitle !== '') {
+ $titleRow .= ' '.PHP_EOL;
+ $titleRow .= " | $firstTitle | ".PHP_EOL;
+ $titleRow .= " $secondTitle | ".PHP_EOL;
+ $titleRow .= '
'.PHP_EOL;
+ }
+
+ $codeRow = '';
+ if ($first !== '' || $second !== '') {
+ $codeRow .= ' '.PHP_EOL;
+ $codeRow .= '| '.PHP_EOL.PHP_EOL;
+ $codeRow .= " $first".PHP_EOL.PHP_EOL;
+ $codeRow .= ' | '.PHP_EOL;
+ $codeRow .= ''.PHP_EOL.PHP_EOL;
+ $codeRow .= " $second".PHP_EOL.PHP_EOL;
+ $codeRow .= ' | '.PHP_EOL;
+ $codeRow .= '
'.PHP_EOL;
+ }
+
+ $output = '';
+ if ($titleRow !== '' || $codeRow !== '') {
+ $output .= ' '.PHP_EOL;
+ $output .= $titleRow;
+ $output .= $codeRow;
+ $output .= '
'.PHP_EOL;
+ }
return $output;
diff --git a/src/Generators/Text.php b/src/Generators/Text.php
index 486e76c7f9..7dc519012e 100644
--- a/src/Generators/Text.php
+++ b/src/Generators/Text.php
@@ -277,56 +277,66 @@ protected function getFormattedCodeComparisonBlock(DOMNode $node)
$second = str_replace('', '', $second);
$secondLines = explode("\n", $second);
- $maxCodeLines = max(count($firstLines), count($secondLines));
- $maxTitleLines = max(count($firstTitleLines), count($secondTitleLines));
-
- $output = str_repeat('-', 41);
- $output .= ' CODE COMPARISON ';
- $output .= str_repeat('-', 42).PHP_EOL;
-
- for ($i = 0; $i < $maxTitleLines; $i++) {
- if (isset($firstTitleLines[$i]) === true) {
- $firstLineText = $firstTitleLines[$i];
- } else {
- $firstLineText = '';
- }
-
- if (isset($secondTitleLines[$i]) === true) {
- $secondLineText = $secondTitleLines[$i];
- } else {
- $secondLineText = '';
- }
-
- $output .= '| ';
- $output .= $firstLineText.str_repeat(' ', (46 - strlen($firstLineText)));
- $output .= ' | ';
- $output .= $secondLineText.str_repeat(' ', (47 - strlen($secondLineText)));
- $output .= ' |'.PHP_EOL;
- }//end for
-
- $output .= str_repeat('-', 100).PHP_EOL;
+ $titleRow = '';
+ if ($firstTitle !== '' || $secondTitle !== '') {
+ $maxTitleLines = max(count($firstTitleLines), count($secondTitleLines));
+ for ($i = 0; $i < $maxTitleLines; $i++) {
+ if (isset($firstTitleLines[$i]) === true) {
+ $firstLineText = $firstTitleLines[$i];
+ } else {
+ $firstLineText = '';
+ }
- for ($i = 0; $i < $maxCodeLines; $i++) {
- if (isset($firstLines[$i]) === true) {
- $firstLineText = $firstLines[$i];
- } else {
- $firstLineText = '';
- }
+ if (isset($secondTitleLines[$i]) === true) {
+ $secondLineText = $secondTitleLines[$i];
+ } else {
+ $secondLineText = '';
+ }
- if (isset($secondLines[$i]) === true) {
- $secondLineText = $secondLines[$i];
- } else {
- $secondLineText = '';
- }
+ $titleRow .= '| ';
+ $titleRow .= $firstLineText.str_repeat(' ', (46 - strlen($firstLineText)));
+ $titleRow .= ' | ';
+ $titleRow .= $secondLineText.str_repeat(' ', (47 - strlen($secondLineText)));
+ $titleRow .= ' |'.PHP_EOL;
+ }//end for
+
+ $titleRow .= str_repeat('-', 100).PHP_EOL;
+ }//end if
+
+ $codeRow = '';
+ if ($first !== '' || $second !== '') {
+ $maxCodeLines = max(count($firstLines), count($secondLines));
+ for ($i = 0; $i < $maxCodeLines; $i++) {
+ if (isset($firstLines[$i]) === true) {
+ $firstLineText = $firstLines[$i];
+ } else {
+ $firstLineText = '';
+ }
- $output .= '| ';
- $output .= $firstLineText.str_repeat(' ', max(0, (47 - strlen($firstLineText))));
- $output .= '| ';
- $output .= $secondLineText.str_repeat(' ', max(0, (48 - strlen($secondLineText))));
- $output .= '|'.PHP_EOL;
- }//end for
+ if (isset($secondLines[$i]) === true) {
+ $secondLineText = $secondLines[$i];
+ } else {
+ $secondLineText = '';
+ }
- $output .= str_repeat('-', 100).PHP_EOL.PHP_EOL;
+ $codeRow .= '| ';
+ $codeRow .= $firstLineText.str_repeat(' ', max(0, (47 - strlen($firstLineText))));
+ $codeRow .= '| ';
+ $codeRow .= $secondLineText.str_repeat(' ', max(0, (48 - strlen($secondLineText))));
+ $codeRow .= '|'.PHP_EOL;
+ }//end for
+
+ $codeRow .= str_repeat('-', 100).PHP_EOL.PHP_EOL;
+ }//end if
+
+ $output = '';
+ if ($titleRow !== '' || $codeRow !== '') {
+ $output = str_repeat('-', 41);
+ $output .= ' CODE COMPARISON ';
+ $output .= str_repeat('-', 42).PHP_EOL;
+ $output .= $titleRow;
+ $output .= $codeRow;
+ }
return $output;
diff --git a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoCode.html b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoCode.html
index c1db1a7bb7..ff4d115361 100644
--- a/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoCode.html
+++ b/tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonNoCode.html
@@ -78,10 +78,6 @@ Code Comparison, no code
Valid: no code. |
Invalid: no code. |
-
- |
- |
-