Skip to content

Commit ea90d8a

Browse files
committed
fixing
1 parent e75b91b commit ea90d8a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/HtmlClass.php

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

33
namespace AhjDev\PhpTagMaker;
44

5+
use Countable;
56
use Stringable;
67
use IteratorAggregate;
78

8-
final class HtmlClass implements Stringable, IteratorAggregate
9+
final class HtmlClass implements Stringable, IteratorAggregate, Countable
910
{
1011
private array $classList = [];
1112

@@ -65,6 +66,11 @@ public function asArray(): array
6566
return $this->classList;
6667
}
6768

69+
public function count(): int
70+
{
71+
return count($this->classList);
72+
}
73+
6874
public function getIterator(): \Generator
6975
{
7076
return yield from $this->classList;

src/Node/HtmlTag.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ public function setName(string $tag): self
5757
public function toDomNode(): DOMElement
5858
{
5959
$element = $this->domElement->cloneNode(true);
60-
$element->setAttribute('class', (string)$this->class);
60+
if ($this->class->count()) {
61+
$element->setAttribute('class', (string) $this->class);
62+
}
6163
array_map(
62-
static fn (Node $v) => $element->append(
63-
$v->toDomNode()
64-
),
64+
static fn (Node $v) => $element->append($v->toDomNode()),
6565
$this->values
6666
);
6767
return $element;

0 commit comments

Comments
 (0)