File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace AhjDev \PhpTagMaker ;
4
4
5
+ use Countable ;
5
6
use Stringable ;
6
7
use IteratorAggregate ;
7
8
8
- final class HtmlClass implements Stringable, IteratorAggregate
9
+ final class HtmlClass implements Stringable, IteratorAggregate, Countable
9
10
{
10
11
private array $ classList = [];
11
12
@@ -65,6 +66,11 @@ public function asArray(): array
65
66
return $ this ->classList ;
66
67
}
67
68
69
+ public function count (): int
70
+ {
71
+ return count ($ this ->classList );
72
+ }
73
+
68
74
public function getIterator (): \Generator
69
75
{
70
76
return yield from $ this ->classList ;
Original file line number Diff line number Diff line change @@ -57,11 +57,11 @@ public function setName(string $tag): self
57
57
public function toDomNode (): DOMElement
58
58
{
59
59
$ 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
+ }
61
63
array_map (
62
- static fn (Node $ v ) => $ element ->append (
63
- $ v ->toDomNode ()
64
- ),
64
+ static fn (Node $ v ) => $ element ->append ($ v ->toDomNode ()),
65
65
$ this ->values
66
66
);
67
67
return $ element ;
You can’t perform that action at this time.
0 commit comments