22namespace PHPHtmlParser ;
33
44use PHPHtmlParser \Dom \AbstractNode ;
5+ use PHPHtmlParser \Dom \Collection ;
56use PHPHtmlParser \Dom \HtmlNode ;
67use PHPHtmlParser \Dom \TextNode ;
8+ use PHPHtmlParser \Exceptions \ChildNotFoundException ;
9+ use PHPHtmlParser \Exceptions \CircularException ;
10+ use PHPHtmlParser \Exceptions \CurlException ;
711use PHPHtmlParser \Exceptions \NotLoadedException ;
12+ use PHPHtmlParser \Exceptions \ParentNotFoundException ;
813use PHPHtmlParser \Exceptions \StrictException ;
14+ use PHPHtmlParser \Exceptions \UnknownChildTypeException ;
915use stringEncode \Encode ;
1016
1117/**
@@ -109,6 +115,8 @@ class Dom
109115 * Returns the inner html of the root node.
110116 *
111117 * @return string
118+ * @throws ChildNotFoundException
119+ * @throws UnknownChildTypeException
112120 */
113121 public function __toString (): string
114122 {
@@ -128,11 +136,13 @@ public function __get($name)
128136
129137 /**
130138 * Attempts to load the dom from any resource, string, file, or URL.
131- *
132139 * @param string $str
133- * @param array $options
140+ * @param array $options
134141 * @return Dom
135- * @chainable
142+ * @throws ChildNotFoundException
143+ * @throws CircularException
144+ * @throws CurlException
145+ * @throws StrictException
136146 */
137147 public function load (string $ str , array $ options = []): Dom
138148 {
@@ -151,11 +161,12 @@ public function load(string $str, array $options = []): Dom
151161
152162 /**
153163 * Loads the dom from a document file/url
154- *
155164 * @param string $file
156- * @param array $options
165+ * @param array $options
157166 * @return Dom
158- * @chainable
167+ * @throws ChildNotFoundException
168+ * @throws CircularException
169+ * @throws StrictException
159170 */
160171 public function loadFromFile (string $ file , array $ options = []): Dom
161172 {
@@ -165,12 +176,14 @@ public function loadFromFile(string $file, array $options = []): Dom
165176 /**
166177 * Use a curl interface implementation to attempt to load
167178 * the content from a url.
168- *
169- * @param string $url
170- * @param array $options
171- * @param CurlInterface $curl
179+ * @param string $url
180+ * @param array $options
181+ * @param CurlInterface|null $curl
172182 * @return Dom
173- * @chainable
183+ * @throws ChildNotFoundException
184+ * @throws CircularException
185+ * @throws CurlException
186+ * @throws StrictException
174187 */
175188 public function loadFromUrl (string $ url , array $ options = [], CurlInterface $ curl = null ): Dom
176189 {
@@ -186,11 +199,12 @@ public function loadFromUrl(string $url, array $options = [], CurlInterface $cur
186199 /**
187200 * Parsers the html of the given string. Used for load(), loadFromFile(),
188201 * and loadFromUrl().
189- *
190202 * @param string $str
191- * @param array $option
203+ * @param array $option
192204 * @return Dom
193- * @chainable
205+ * @throws ChildNotFoundException
206+ * @throws CircularException
207+ * @throws StrictException
194208 */
195209 public function loadStr (string $ str , array $ option = []): Dom
196210 {
@@ -228,10 +242,11 @@ public function setOptions(array $options): Dom
228242
229243 /**
230244 * Find elements by css selector on the root node.
231- *
232- * @param string $selector
233- * @param int $nth
234- * @return mixed
245+ * @param string $selector
246+ * @param int|null $nth
247+ * @return mixed|Collection|null
248+ * @throws ChildNotFoundException
249+ * @throws NotLoadedException
235250 */
236251 public function find (string $ selector , int $ nth = null )
237252 {
@@ -242,9 +257,11 @@ public function find(string $selector, int $nth = null)
242257
243258 /**
244259 * Find element by Id on the root node
245- *
246260 * @param int $id
247- * @return mixed
261+ * @return bool|AbstractNode
262+ * @throws ChildNotFoundException
263+ * @throws NotLoadedException
264+ * @throws ParentNotFoundException
248265 */
249266 public function findById (int $ id )
250267 {
@@ -356,10 +373,11 @@ public function clearNoSlashTags(): Dom
356373
357374 /**
358375 * Simple wrapper function that returns the first child.
359- *
360- * @return \PHPHtmlParser\Dom\AbstractNode
376+ * @return AbstractNode
377+ * @throws ChildNotFoundException
378+ * @throws NotLoadedException
361379 */
362- public function firstChild (): \ PHPHtmlParser \ Dom \ AbstractNode
380+ public function firstChild (): AbstractNode
363381 {
364382 $ this ->isLoaded ();
365383
@@ -368,10 +386,11 @@ public function firstChild(): \PHPHtmlParser\Dom\AbstractNode
368386
369387 /**
370388 * Simple wrapper function that returns the last child.
371- *
372- * @return \PHPHtmlParser\Dom\AbstractNode
389+ * @return AbstractNode
390+ * @throws ChildNotFoundException
391+ * @throws NotLoadedException
373392 */
374- public function lastChild (): \ PHPHtmlParser \ Dom \ AbstractNode
393+ public function lastChild (): AbstractNode
375394 {
376395 $ this ->isLoaded ();
377396
@@ -382,6 +401,7 @@ public function lastChild(): \PHPHtmlParser\Dom\AbstractNode
382401 * Simple wrapper function that returns count of child elements
383402 *
384403 * @return int
404+ * @throws NotLoadedException
385405 */
386406 public function countChildren (): int
387407 {
@@ -394,6 +414,7 @@ public function countChildren(): int
394414 * Get array of children
395415 *
396416 * @return array
417+ * @throws NotLoadedException
397418 */
398419 public function getChildren (): array
399420 {
@@ -406,6 +427,7 @@ public function getChildren(): array
406427 * Check if node have children nodes
407428 *
408429 * @return bool
430+ * @throws NotLoadedException
409431 */
410432 public function hasChildren (): bool
411433 {
@@ -417,9 +439,10 @@ public function hasChildren(): bool
417439 /**
418440 * Simple wrapper function that returns an element by the
419441 * id.
420- *
421- * @param string $id
422- * @return \PHPHtmlParser\Dom\AbstractNode|null
442+ * @param $id
443+ * @return mixed|Collection|null
444+ * @throws ChildNotFoundException
445+ * @throws NotLoadedException
423446 */
424447 public function getElementById ($ id )
425448 {
@@ -431,9 +454,10 @@ public function getElementById($id)
431454 /**
432455 * Simple wrapper function that returns all elements by
433456 * tag name.
434- *
435457 * @param string $name
436- * @return mixed
458+ * @return mixed|Collection|null
459+ * @throws ChildNotFoundException
460+ * @throws NotLoadedException
437461 */
438462 public function getElementsByTag (string $ name )
439463 {
@@ -445,9 +469,10 @@ public function getElementsByTag(string $name)
445469 /**
446470 * Simple wrapper function that returns all elements by
447471 * class name.
448- *
449472 * @param string $class
450- * @return mixed
473+ * @return mixed|Collection|null
474+ * @throws ChildNotFoundException
475+ * @throws NotLoadedException
451476 */
452477 public function getElementsByClass (string $ class )
453478 {
@@ -528,6 +553,11 @@ protected function clean(string $str): string
528553
529554 /**
530555 * Attempts to parse the html in content.
556+ *
557+ * @return void
558+ * @throws ChildNotFoundException
559+ * @throws CircularException
560+ * @throws StrictException
531561 */
532562 protected function parse (): void
533563 {
@@ -632,7 +662,7 @@ protected function parseTag(): array
632662 $ tag = strtolower ($ this ->content ->copyByToken ('slash ' , true ));
633663 if (trim ($ tag ) == '' )
634664 {
635- // no tag found, invalide < found
665+ // no tag found, invalid < found
636666 return $ return ;
637667 }
638668 $ node = new HtmlNode ($ tag );
@@ -746,6 +776,7 @@ protected function parseTag(): array
746776 * Attempts to detect the charset that the html was sent in.
747777 *
748778 * @return bool
779+ * @throws ChildNotFoundException
749780 */
750781 protected function detectCharset (): bool
751782 {
0 commit comments