Skip to content

Commit b53bc38

Browse files
committed
Generators/Text::codeTitleToLines(): simplify the logic
There's absolutely no need for custom word-wrapping logic when PHP contains a function which can do this perfectly well.
1 parent 5998203 commit b53bc38

File tree

1 file changed

+2
-28
lines changed

1 file changed

+2
-28
lines changed

src/Generators/Text.php

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -268,35 +268,9 @@ private function codeTitleToLines(DOMElement $codeElm)
268268
return [];
269269
}
270270

271-
$titleLines = [];
272-
$tempTitle = '';
273-
$words = explode(' ', $title);
274-
275-
foreach ($words as $word) {
276-
if (strlen($tempTitle.$word) >= 45) {
277-
if (strlen($tempTitle.$word) === 45) {
278-
// Adding the extra space will push us to the edge
279-
// so we are done.
280-
$titleLines[] = $tempTitle.$word;
281-
$tempTitle = '';
282-
} else if (strlen($tempTitle.$word) === 46) {
283-
// We are already at the edge, so we are done.
284-
$titleLines[] = $tempTitle.$word;
285-
$tempTitle = '';
286-
} else {
287-
$titleLines[] = $tempTitle;
288-
$tempTitle = $word.' ';
289-
}
290-
} else {
291-
$tempTitle .= $word.' ';
292-
}
293-
}//end foreach
294-
295-
if ($tempTitle !== '') {
296-
$titleLines[] = $tempTitle;
297-
}
271+
$title = wordwrap($title, 46, "\n");
298272

299-
return $titleLines;
273+
return explode("\n", $title);
300274

301275
}//end codeTitleToLines()
302276

0 commit comments

Comments
 (0)