22namespace PHPHtmlParser \Dom ;
33
44use PHPHtmlParser \Selector ;
5+ use PHPHtmlParser \Exceptions \ChildNotFoundException ;
6+ use PHPHtmlParser \Exceptions \CircularException ;
7+ use PHPHtmlParser \Exceptions \ParentNotFoundException ;
58use stringEncode \Encode ;
69
710/**
@@ -130,14 +133,14 @@ public function getParent()
130133 *
131134 * @param AbstractNode $parent
132135 * @chainable
133- * @throws Exception
136+ * @throws CircularException
134137 */
135138 public function setParent (AbstractNode $ parent )
136139 {
137140 // check integrity
138141 if ($ this ->isDescendant ($ parent ->id ()))
139142 {
140- throw new Exception ('Can not add descendant " ' .$ parent ->id ().'" as my parent. ' );
143+ throw new CircularException ('Can not add descendant " ' .$ parent ->id ().'" as my parent. ' );
141144 }
142145
143146 // remove from old parent
@@ -195,13 +198,13 @@ public function hasChildren()
195198 *
196199 * @param int $id
197200 * @return AbstractNode
198- * @throw Exception
201+ * @throws ChildNotFoundException
199202 */
200203 public function getChild ($ id )
201204 {
202205 if ( ! isset ($ this ->children [$ id ]))
203206 {
204- throw new Exception ( ' Child " ' . $ id. ' " not found in this node.' );
207+ throw new ChildNotFoundException ( " Child ' $ id' not found in this node." );
205208 }
206209
207210 return $ this ->children [$ id ]['node ' ];
@@ -213,6 +216,7 @@ public function getChild($id)
213216 *
214217 * @param AbstractNode $child
215218 * @return bool
219+ * @throws CircularExceptionException
216220 */
217221 public function addChild (AbstractNode $ child )
218222 {
@@ -222,13 +226,13 @@ public function addChild(AbstractNode $child)
222226 // check integrity
223227 if ($ this ->isAncestor ($ child ->id ()))
224228 {
225- throw new Exception ('Can not add child. It is my ancestor. ' );
229+ throw new CircularException ('Can not add child. It is my ancestor. ' );
226230 }
227231
228232 // check if child is itself
229233 if ($ child ->id () == $ this ->id )
230234 {
231- throw new Exception ('Can not set itself as a child. ' );
235+ throw new CircularException ('Can not set itself as a child. ' );
232236 }
233237
234238 if ($ this ->hasChildren ())
@@ -416,13 +420,13 @@ public function lastChild()
416420 * Attempts to get the next sibling.
417421 *
418422 * @return AbstractNode
419- * @throws Exception
423+ * @throws ParentNotFoundException
420424 */
421425 public function nextSibling ()
422426 {
423427 if (is_null ($ this ->parent ))
424428 {
425- throw new Exception ('Parent is not set for this node. ' );
429+ throw new ParentNotFoundException ('Parent is not set for this node. ' );
426430 }
427431
428432 return $ this ->parent ->nextChild ($ this ->id );
@@ -432,13 +436,13 @@ public function nextSibling()
432436 * Attempts to get the previous sibling
433437 *
434438 * @return AbstractNode
435- * @throw Exception
439+ * @throws ParentNotFoundException
436440 */
437441 public function previousSibling ()
438442 {
439443 if (is_null ($ this ->parent ))
440444 {
441- throw new Exception ('Parent is not set for this node. ' );
445+ throw new ParentNotFoundException ('Parent is not set for this node. ' );
442446 }
443447
444448 return $ this ->parent ->previousChild ($ this ->id );
@@ -493,7 +497,7 @@ public function getAttribute($key)
493497 *
494498 * @param string $tag
495499 * @return AbstractNode
496- * @throws Exception
500+ * @throws ParentNotFoundException
497501 */
498502 public function ancestorByTag ($ tag )
499503 {
@@ -510,7 +514,7 @@ public function ancestorByTag($tag)
510514 $ node = $ node ->getParent ();
511515 }
512516
513- throw new Exception ('Could not find an ancestor with " ' .$ tag .'" tag ' );
517+ throw new ParentNotFoundException ('Could not find an ancestor with " ' .$ tag .'" tag ' );
514518 }
515519
516520 /**
0 commit comments