Skip to content

Commit 2a83e19

Browse files
committed
Add setName method to Tag and type to offsetGet
Introduces a setName method to the Tag class for setting the tag name and returning a cloned instance. Also adds a return type to the offsetGet method in Collection for improved type safety. paquettg#250
1 parent dab7606 commit 2a83e19

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/PHPHtmlParser/Dom/Node/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function offsetUnset($offset): void
134134
* @param mixed $offset
135135
* @return mixed
136136
*/
137-
public function offsetGet($offset)
137+
public function offsetGet($offset): mixed
138138
{
139139
return $this->collection[$offset] ?? null;
140140
}

src/PHPHtmlParser/Dom/Tag.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ public function name(): string
9797
return $this->name;
9898
}
9999

100+
/**
101+
* Sets the name of this tag.
102+
*/
103+
public function setName(string $name): Tag
104+
{
105+
$this->name = $name;
106+
107+
return clone $this;
108+
}
109+
100110
/**
101111
* Sets the tag to be self closing.
102112
*/

0 commit comments

Comments
 (0)