Skip to content

Commit 6ec838a

Browse files
committed
Merge branch 'rnewton-master' into dev/3.0.0
2 parents f110ce0 + 9ea3eee commit 6ec838a

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/PHPHtmlParser/Dom.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public function __get($name)
146146
* @throws CircularException
147147
* @throws CurlException
148148
* @throws StrictException
149+
* @throws LogicalException
149150
*/
150151
public function load(string $str, array $options = []): Dom
151152
{
@@ -607,6 +608,7 @@ protected function clean(string $str): string
607608
* @throws ChildNotFoundException
608609
* @throws CircularException
609610
* @throws StrictException
611+
* @throws LogicalException
610612
*/
611613
protected function parse(): void
612614
{

src/PHPHtmlParser/Dom/AbstractNode.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,27 @@ public function getTag(): Tag
310310
return $this->tag;
311311
}
312312

313+
/**
314+
* Replaces the tag for this node
315+
*
316+
* @param string|Tag $tag
317+
* @return AbstractNode
318+
* @chainable
319+
*/
320+
public function setTag($tag): AbstractNode
321+
{
322+
if (is_string($tag)) {
323+
$tag = new Tag($tag);
324+
}
325+
326+
$this->tag = $tag;
327+
328+
// clear any cache
329+
$this->clear();
330+
331+
return $this;
332+
}
333+
313334
/**
314335
* A wrapper method that simply calls the getAttribute method
315336
* on the tag of this node.

tests/Node/HtmlTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,18 @@ public function testRemoveAllAttributes()
413413
$this->assertEquals(0, \count($node->getAttributes()));
414414
}
415415

416+
public function testSetTag()
417+
{
418+
$node = new HtmlNode('div');
419+
$this->assertEquals('<div></div>', $node->outerHtml());
420+
421+
$node->setTag('p');
422+
$this->assertEquals('<p></p>', $node->outerHtml());
423+
424+
$node->setTag(new Tag('span'));
425+
$this->assertEquals('<span></span>', $node->outerHtml());
426+
}
427+
416428
public function testCountable()
417429
{
418430
$div = new Tag('div');

0 commit comments

Comments
 (0)