File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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 ' );
You can’t perform that action at this time.
0 commit comments