Skip to content

Commit a97683d

Browse files
authored
Merge pull request #824 from PHPCSStandards/feature/generators-text-various-simplifications
Generators/Text: various minor code simplifications
2 parents 2fa51a5 + 4e8113f commit a97683d

File tree

1 file changed

+6
-41
lines changed

1 file changed

+6
-41
lines changed

src/Generators/Text.php

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -130,46 +130,13 @@ protected function getFormattedTextBlock(DOMNode $node)
130130
}
131131

132132
$text = trim($text);
133-
$text = str_replace('<em>', '*', $text);
134-
$text = str_replace('</em>', '*', $text);
133+
$text = str_replace(['<em>', '</em>'], '*', $text);
135134

136135
$nodeLines = explode("\n", $text);
137-
$lines = [];
138-
139-
foreach ($nodeLines as $currentLine) {
140-
$currentLine = trim($currentLine);
141-
if ($currentLine === '') {
142-
// The text contained a blank line. Respect this.
143-
$lines[] = '';
144-
continue;
145-
}
146-
147-
$tempLine = '';
148-
$words = explode(' ', $currentLine);
149-
150-
foreach ($words as $word) {
151-
$currentLength = strlen($tempLine.$word);
152-
if ($currentLength < 99) {
153-
$tempLine .= $word.' ';
154-
continue;
155-
}
156-
157-
if ($currentLength === 99 || $currentLength === 100) {
158-
// We are already at the edge, so we are done.
159-
$lines[] = $tempLine.$word;
160-
$tempLine = '';
161-
} else {
162-
$lines[] = rtrim($tempLine);
163-
$tempLine = $word.' ';
164-
}
165-
}//end foreach
166-
167-
if ($tempLine !== '') {
168-
$lines[] = rtrim($tempLine);
169-
}
170-
}//end foreach
136+
$nodeLines = array_map('trim', $nodeLines);
137+
$text = implode(PHP_EOL, $nodeLines);
171138

172-
return implode(PHP_EOL, $lines).PHP_EOL.PHP_EOL;
139+
return wordwrap($text, 100, PHP_EOL).PHP_EOL.PHP_EOL;
173140

174141
}//end getFormattedTextBlock()
175142

@@ -243,8 +210,7 @@ protected function getFormattedCodeComparisonBlock(DOMNode $node)
243210
$firstTitleLines[] = $tempTitle;
244211
}
245212

246-
$first = str_replace('<em>', '', $first);
247-
$first = str_replace('</em>', '', $first);
213+
$first = str_replace(['<em>', '</em>'], '', $first);
248214
$firstLines = explode("\n", $first);
249215

250216
$second = trim($secondCodeElm->nodeValue);
@@ -278,8 +244,7 @@ protected function getFormattedCodeComparisonBlock(DOMNode $node)
278244
$secondTitleLines[] = $tempTitle;
279245
}
280246

281-
$second = str_replace('<em>', '', $second);
282-
$second = str_replace('</em>', '', $second);
247+
$second = str_replace(['<em>', '</em>'], '', $second);
283248
$secondLines = explode("\n", $second);
284249

285250
$titleRow = '';

0 commit comments

Comments
 (0)