Skip to content

Commit f447a16

Browse files
committed
Updated doc blocks
1 parent 7b31b45 commit f447a16

19 files changed

+264
-188
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- Moved the Mock object to the tests directory, where it belongs.
2323
- Changes from `PSR-0` to `PSR-4` autoloading.
2424
- Updated `CONTRIBUTING.md` contents.
25+
- Updated docblocks.

src/PHPHtmlParser/Dom.php

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
namespace PHPHtmlParser;
33

44
use PHPHtmlParser\Dom\AbstractNode;
5+
use PHPHtmlParser\Dom\Collection;
56
use PHPHtmlParser\Dom\HtmlNode;
67
use PHPHtmlParser\Dom\TextNode;
8+
use PHPHtmlParser\Exceptions\ChildNotFoundException;
9+
use PHPHtmlParser\Exceptions\CircularException;
10+
use PHPHtmlParser\Exceptions\CurlException;
711
use PHPHtmlParser\Exceptions\NotLoadedException;
12+
use PHPHtmlParser\Exceptions\ParentNotFoundException;
813
use PHPHtmlParser\Exceptions\StrictException;
14+
use PHPHtmlParser\Exceptions\UnknownChildTypeException;
915
use 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
{

src/PHPHtmlParser/Dom/AbstractNode.php

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@
1111

1212
/**
1313
* Dom node object.
14-
*
15-
* @property string outerhtml
16-
* @property string innerhtml
17-
* @property string text
18-
* @property int prev
19-
* @property int next
20-
* @property \PHPHtmlParser\Dom\Tag tag
14+
* @property string outerhtml
15+
* @property string innerhtml
16+
* @property string text
17+
* @property int prev
18+
* @property int next
19+
* @property Tag tag
2120
* @property InnerNode parent
2221
*/
2322
abstract class AbstractNode
2423
{
2524
private static $count = 0;
2625
/**
2726
* Contains the tag name/type
28-
*
29-
* @var \PHPHtmlParser\Dom\Tag
27+
* @var Tag
3028
*/
3129
protected $tag;
3230

@@ -170,11 +168,10 @@ public function getParent()
170168

171169
/**
172170
* Sets the parent node.
173-
*
174171
* @param InnerNode $parent
175172
* @return AbstractNode
173+
* @throws ChildNotFoundException
176174
* @throws CircularException
177-
* @chainable
178175
*/
179176
public function setParent(InnerNode $parent): AbstractNode
180177
{
@@ -286,8 +283,8 @@ public function hasNextSibling(): bool
286283

287284
/**
288285
* Attempts to get the next sibling.
289-
*
290286
* @return AbstractNode
287+
* @throws ChildNotFoundException
291288
* @throws ParentNotFoundException
292289
*/
293290
public function nextSibling(): AbstractNode
@@ -300,9 +297,9 @@ public function nextSibling(): AbstractNode
300297
}
301298

302299
/**
303-
* Attempts to get the previous sibling
304-
*
300+
* Attempts to get the previous sibling.
305301
* @return AbstractNode
302+
* @throws ChildNotFoundException
306303
* @throws ParentNotFoundException
307304
*/
308305
public function previousSibling(): AbstractNode
@@ -441,11 +438,11 @@ public function ancestorByTag(string $tag): AbstractNode
441438

442439
/**
443440
* Find elements by css selector
444-
*
445-
* @param string $selector
446-
* @param int $nth
447-
* @param bool $depthFirst
448-
* @return mixed
441+
* @param string $selector
442+
* @param int|null $nth
443+
* @param bool $depthFirst
444+
* @return mixed|Collection|null
445+
* @throws ChildNotFoundException
449446
*/
450447
public function find(string $selector, int $nth = null, bool $depthFirst = false)
451448
{
@@ -467,9 +464,10 @@ public function find(string $selector, int $nth = null, bool $depthFirst = false
467464

468465
/**
469466
* Find node by id
470-
*
471467
* @param int $id
472468
* @return bool|AbstractNode
469+
* @throws ChildNotFoundException
470+
* @throws ParentNotFoundException
473471
*/
474472
public function findById(int $id)
475473
{

src/PHPHtmlParser/Dom/Collection.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public function __get($key)
6464
* the collection.
6565
*
6666
* @return string
67-
* @throws EmptyCollectionException
6867
*/
6968
public function __toString(): string
7069
{

src/PHPHtmlParser/Dom/HtmlNode.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public function setHtmlSpecialCharsDecode($htmlSpecialCharsDecode = false): void
6767

6868
/**
6969
* Gets the inner html of this node.
70-
*
7170
* @return string
71+
* @throws ChildNotFoundException
7272
* @throws UnknownChildTypeException
7373
*/
7474
public function innerHtml(): string
@@ -113,8 +113,9 @@ public function innerHtml(): string
113113
/**
114114
* Gets the html of this node, including it's own
115115
* tag.
116-
*
117116
* @return string
117+
* @throws ChildNotFoundException
118+
* @throws UnknownChildTypeException
118119
*/
119120
public function outerHtml(): string
120121
{

0 commit comments

Comments
 (0)