Skip to content

Commit ef7e94d

Browse files
authored
Merge pull request #819 from PHPCSStandards/feature/generators-dont-print-stnd-when-empty
Generators: don't print standard when it's empty
2 parents 530cc74 + b28fd21 commit ef7e94d

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

src/Generators/HTML.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,12 @@ protected function printTextBlock(DOMNode $node)
318318
*/
319319
protected function getFormattedTextBlock(DOMNode $node)
320320
{
321-
$content = trim($node->nodeValue);
321+
$content = $node->nodeValue;
322+
if (empty($content) === true) {
323+
return '';
324+
}
325+
326+
$content = trim($content);
322327
$content = htmlspecialchars($content, (ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401));
323328

324329
// Allow only em tags.

src/Generators/Markdown.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,12 @@ protected function printTextBlock(DOMNode $node)
178178
*/
179179
protected function getFormattedTextBlock(DOMNode $node)
180180
{
181-
$content = trim($node->nodeValue);
181+
$content = $node->nodeValue;
182+
if (empty($content) === true) {
183+
return '';
184+
}
185+
186+
$content = trim($content);
182187
$content = htmlspecialchars($content, (ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401));
183188
$content = str_replace('<em>', '*', $content);
184189
$content = str_replace('</em>', '*', $content);

src/Generators/Text.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ protected function printTextBlock(DOMNode $node)
124124
*/
125125
protected function getFormattedTextBlock(DOMNode $node)
126126
{
127-
$text = trim($node->nodeValue);
127+
$text = $node->nodeValue;
128+
if (empty($text) === true) {
129+
return '';
130+
}
131+
132+
$text = trim($text);
128133
$text = str_replace('<em>', '*', $text);
129134
$text = str_replace('</em>', '*', $text);
130135

tests/Core/Generators/Expectations/ExpectedOutputInvalidStandardNoContent.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
<h1>GeneratorTest Coding Standards</h1>
7373
<a name="Standard-Element,-no-content" />
7474
<h2>Standard Element, no content</h2>
75-
<p class="text"></p>
7675
<table class="code-comparison">
7776
<tr>
7877
<td class="code-comparison-title">Valid: Lorem ipsum dolor sit amet.</td>

tests/Core/Generators/Expectations/ExpectedOutputInvalidStandardNoContent.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
## Standard Element, no content
44

5-
65
<table>
76
<tr>
87
<th>Valid: Lorem ipsum dolor sit amet.</th>

tests/Core/Generators/Expectations/ExpectedOutputInvalidStandardNoContent.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
| GENERATORTEST CODING STANDARD: STANDARD ELEMENT, NO CONTENT |
44
---------------------------------------------------------------
55

6-
7-
86
----------------------------------------- CODE COMPARISON ------------------------------------------
97
| Valid: Lorem ipsum dolor sit amet. | Invalid: Maecenas non rutrum dolor. |
108
----------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)