Skip to content

Commit 4d534fe

Browse files
authored
refactor(view): use is_self_closing_tag where relevant (#1035)
1 parent 2279402 commit 4d534fe

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/Tempest/View/src/Elements/GenericElement.php

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

77
use Tempest\View\Element;
88

9+
use function Tempest\Support\Html\is_self_closing_tag;
910
use function Tempest\Support\str;
1011

1112
final class GenericElement implements Element
@@ -68,7 +69,7 @@ public function compile(): string
6869
}
6970

7071
// Void elements
71-
if (in_array($this->tag, ['br', 'hr', 'img', 'input', 'link', 'meta', 'area', 'base', 'col', 'embed', 'source', 'track', 'wbr'])) {
72+
if (is_self_closing_tag($this->tag)) {
7273
return "<{$this->tag}{$attributes}>";
7374
}
7475

src/Tempest/View/src/Exceptions/InvalidDataAttribute.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Tempest\View\Exceptions;
46

57
use Exception;

src/Tempest/View/src/Renderers/TempestViewCompiler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Dom\NodeList;
99
use Stringable;
1010
use Tempest\Core\Kernel;
11-
use Tempest\Debug\DOMDebug;
1211
use Tempest\Discovery\DiscoveryLocation;
1312
use Tempest\Mapper\Exceptions\ViewNotFound;
1413
use Tempest\Support\Str\ImmutableString;
@@ -18,6 +17,7 @@
1817
use Tempest\View\View;
1918

2019
use function Tempest\Support\arr;
20+
use function Tempest\Support\Html\is_self_closing_tag;
2121
use function Tempest\Support\path;
2222
use function Tempest\Support\str;
2323

@@ -113,7 +113,7 @@ private function parseDom(string $template): NodeList
113113
replace: function (array $match) {
114114
$element = str($match['element'])->trim();
115115

116-
if (in_array($element, ['br', 'hr', 'img', 'input', 'link', 'meta', 'area', 'base', 'col', 'embed', 'source', 'track', 'wbr'])) {
116+
if (is_self_closing_tag($element)) {
117117
// Void tags must not have a closing tag
118118
return sprintf('<%s>', $element->toString());
119119
}

0 commit comments

Comments
 (0)