Skip to content

Commit 8afa2d8

Browse files
committed
Html: simplified code
1 parent ab1d0b8 commit 8afa2d8

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/Utils/Html.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ final public function setHtml($html)
289289
if (is_array($html)) {
290290
throw new Nette\InvalidArgumentException(sprintf('Textual content must be a scalar, %s given.', gettype($html)));
291291
}
292-
$this->removeChildren();
293-
$this->children[] = (string) $html;
292+
$this->children = [(string) $html];
294293
return $this;
295294
}
296295

@@ -300,15 +299,7 @@ final public function setHtml($html)
300299
*/
301300
final public function getHtml(): string
302301
{
303-
$s = '';
304-
foreach ($this->children as $child) {
305-
if (is_object($child)) {
306-
$s .= $child->render();
307-
} else {
308-
$s .= $child;
309-
}
310-
}
311-
return $s;
302+
return implode('', $this->children);
312303
}
313304

314305

@@ -323,7 +314,8 @@ final public function setText($text)
323314
if (!$text instanceof IHtmlString) {
324315
$text = htmlspecialchars((string) $text, ENT_NOQUOTES, 'UTF-8');
325316
}
326-
return $this->setHtml((string) $text);
317+
$this->children = [(string) $text];
318+
return $this;
327319
}
328320

329321

0 commit comments

Comments
 (0)