Skip to content

Commit 1e0e1c9

Browse files
committed
Updated in code documentation
1 parent 31f1b09 commit 1e0e1c9

File tree

12 files changed

+84
-50
lines changed

12 files changed

+84
-50
lines changed

src/PHPHtmlParser/Content.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function char($char = null)
7272
* Moves the current position forward.
7373
*
7474
* @param int $count
75-
* @chainable
75+
* @return $this
7676
*/
7777
public function fastForward($count)
7878
{
@@ -84,7 +84,7 @@ public function fastForward($count)
8484
* Moves the current position backward.
8585
*
8686
* @param int $count
87-
* @chainable
87+
* @return $this
8888
*/
8989
public function rewind($count)
9090
{

src/PHPHtmlParser/Dom.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ public function __get($name)
108108
* Attempts to load the dom from any resource, string, file, or URL.
109109
*
110110
* @param string $str
111-
* @param array $option
112-
* @chainable
111+
* @param array $options
112+
* @return $this
113113
*/
114114
public function load($str, $options = [])
115115
{
@@ -131,8 +131,8 @@ public function load($str, $options = [])
131131
* Loads the dom from a document file/url
132132
*
133133
* @param string $file
134-
* @param array $option
135-
* @chainable
134+
* @param array $options
135+
* @return $this
136136
*/
137137
public function loadFromFile($file, $options = [])
138138
{
@@ -144,9 +144,9 @@ public function loadFromFile($file, $options = [])
144144
* the content from a url.
145145
*
146146
* @param string $url
147-
* @param array $option
147+
* @param array $options
148148
* @param CurlInterface $curl
149-
* @chainable
149+
* @return $this
150150
*/
151151
public function loadFromUrl($url, $options = [], CurlInterface $curl = null)
152152
{
@@ -166,7 +166,7 @@ public function loadFromUrl($url, $options = [], CurlInterface $curl = null)
166166
*
167167
* @param string $str
168168
* @param array $option
169-
* @chainable
169+
* @return $this
170170
*/
171171
public function loadStr($str, $option)
172172
{
@@ -192,7 +192,7 @@ public function loadStr($str, $option)
192192
* Sets a global options array to be used by all load calls.
193193
*
194194
* @param array $options
195-
* @chainable
195+
* @return $this
196196
*/
197197
public function setOptions(array $options)
198198
{
@@ -218,7 +218,7 @@ public function find($selector, $nth = null)
218218
* be self closing.
219219
*
220220
* @param string|array $tag
221-
* @chainable
221+
* @return $this
222222
*/
223223
public function addSelfClosingTag($tag)
224224
{
@@ -238,7 +238,7 @@ public function addSelfClosingTag($tag)
238238
* always be self closing.
239239
*
240240
* @param string|array $tag
241-
* @chainable
241+
* @return $this
242242
*/
243243
public function removeSelfClosingTag($tag)
244244
{
@@ -253,7 +253,7 @@ public function removeSelfClosingTag($tag)
253253
/**
254254
* Sets the list of self closing tags to empty.
255255
*
256-
* @chainable
256+
* @return $this
257257
*/
258258
public function clearSelfClosingTags()
259259
{
@@ -264,7 +264,7 @@ public function clearSelfClosingTags()
264264
/**
265265
* Simple wrapper function that returns the first child.
266266
*
267-
* @return Node
267+
* @return \PHPHtmlParser\Dom\AbstractNode
268268
*/
269269
public function firstChild()
270270
{
@@ -275,7 +275,7 @@ public function firstChild()
275275
/**
276276
* Simple wrapper function that returns the last child.
277277
*
278-
* @return AbstractNode
278+
* @return \PHPHtmlParser\Dom\AbstractNode
279279
*/
280280
public function lastChild()
281281
{
@@ -287,7 +287,8 @@ public function lastChild()
287287
* Simple wrapper function that returns an element by the
288288
* id.
289289
*
290-
* @return AbstractNode
290+
* @param string $id
291+
* @return \PHPHtmlParser\Dom\AbstractNode
291292
*/
292293
public function getElementById($id)
293294
{
@@ -298,7 +299,8 @@ public function getElementById($id)
298299
/**
299300
* Simple wrapper function that returns all elements by
300301
* tag name.
301-
*
302+
*
303+
* @param string $name
302304
* @return array
303305
*/
304306
public function getElementsByTag($name)
@@ -311,6 +313,7 @@ public function getElementsByTag($name)
311313
* Simple wrapper function that returns all elements by
312314
* class name.
313315
*
316+
* @param string $class
314317
* @return array
315318
*/
316319
public function getElementsByClass($class)
@@ -442,7 +445,8 @@ protected function parse()
442445
* Attempt to parse a tag out of the content.
443446
*
444447
* @return array
445-
*/
448+
* @throws StrictException
449+
*/
446450
protected function parseTag()
447451
{
448452
$return = [

src/PHPHtmlParser/Dom/AbstractNode.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class AbstractNode {
1919
/**
2020
* Contains the tag name/type
2121
*
22-
* @var string
22+
* @var \PHPHtmlParser\Dom\Tag
2323
*/
2424
protected $tag;
2525

@@ -40,7 +40,7 @@ abstract class AbstractNode {
4040
/**
4141
* Contains the parent Node.
4242
*
43-
* @var Node
43+
* @var AbstractNode
4444
*/
4545
protected $parent = null;
4646

@@ -121,7 +121,7 @@ public function id()
121121
/**
122122
* Returns the parent of node.
123123
*
124-
* @return Node
124+
* @return AbstractNode
125125
*/
126126
public function getParent()
127127
{
@@ -132,7 +132,7 @@ public function getParent()
132132
* Sets the parent node.
133133
*
134134
* @param AbstractNode $parent
135-
* @chainable
135+
* @return $this
136136
* @throws CircularException
137137
*/
138138
public function setParent(AbstractNode $parent)
@@ -251,12 +251,11 @@ public function countChildren()
251251
*
252252
* @param AbstractNode $child
253253
* @return bool
254-
* @throws CircularExceptionException
254+
* @throws CircularException
255255
*/
256256
public function addChild(AbstractNode $child)
257257
{
258-
$key = null;
259-
$newKey = 0;
258+
$key = null;
260259

261260
// check integrity
262261
if ($this->isAncestor($child->id()))
@@ -302,7 +301,7 @@ public function addChild(AbstractNode $child)
302301
* Removes the child by id.
303302
*
304303
* @param int $id
305-
* @chainable
304+
* @return $this
306305
*/
307306
public function removeChild($id)
308307
{
@@ -533,7 +532,7 @@ public function getAttribute($key)
533532
*
534533
* @param string $key
535534
* @param string $value
536-
* @chainable
535+
* @return $this
537536
*/
538537
public function setAttribute($key, $value)
539538
{

src/PHPHtmlParser/Dom/ArrayNode.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use Countable;
55
use ArrayIterator;
66
use IteratorAggregate;
7-
use PHPHtmlParser\Exceptions\IncorrectChildMethodException;
87

98
/**
109
* Dom node object which will allow users to use it as

src/PHPHtmlParser/Dom/Collection.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use ArrayAccess;
66
use ArrayIterator;
77
use IteratorAggregate;
8+
use PHPHtmlParser\Exceptions\EmptyCollectionException;
89

910
class Collection implements IteratorAggregate, ArrayAccess, Countable {
1011

@@ -22,14 +23,19 @@ class Collection implements IteratorAggregate, ArrayAccess, Countable {
2223
* @param string $method
2324
* @param array $arguments
2425
* @return mixed;
25-
*/
26+
* @throws EmptyCollectionException
27+
*/
2628
public function __call($method, $arguments)
2729
{
2830
$node = reset($this->collection);
2931
if ($node instanceof AbstractNode)
3032
{
3133
return call_user_func_array([$node, $method], $arguments);
3234
}
35+
else
36+
{
37+
throw new EmptyCollectionException('The collection does not contain any Nodes.');
38+
}
3339
}
3440

3541
/**
@@ -38,29 +44,39 @@ public function __call($method, $arguments)
3844
*
3945
* @param mixed $key
4046
* @return mixed
41-
*/
47+
* @throws EmptyCollectionException
48+
*/
4249
public function __get($key)
4350
{
4451
$node = reset($this->collection);
4552
if ($node instanceof AbstractNode)
4653
{
4754
return $node->$key;
4855
}
56+
else
57+
{
58+
throw new EmptyCollectionException('The collection does not contain any Nodes.');
59+
}
4960
}
5061

5162
/**
5263
* Applies the magic string method to the first node in
5364
* the collection.
5465
*
5566
* @return string
56-
*/
67+
* @throws EmptyCollectionException
68+
*/
5769
public function __toString()
5870
{
5971
$node = reset($this->collection);
6072
if ($node instanceof AbstractNode)
6173
{
6274
return (string) $node;
6375
}
76+
else
77+
{
78+
throw new EmptyCollectionException('The collection does not contain any Nodes.');
79+
}
6480
}
6581

6682
/**
@@ -126,9 +142,9 @@ public function offsetUnset($offset)
126142
* Gets a node at the given offset, or null
127143
*
128144
* @param mixed $offset
129-
* @return $offset
145+
* @return mixed
130146
*/
131-
public function offsetGet($offset)
147+
public function offsetGet($offset)
132148
{
133149
return isset($this->collection[$offset]) ? $this->collection[$offset] : null;
134150
}

src/PHPHtmlParser/Dom/HtmlNode.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
class HtmlNode extends ArrayNode {
88

99
/**
10-
* Remembers what the innerHtml was if it was scaned previously.
10+
* Remembers what the innerHtml was if it was scanned previously.
1111
*/
1212
protected $innerHtml = null;
1313

1414
/**
15-
* Remembers what the outerHtml was if it was scaned previously.
15+
* Remembers what the outerHtml was if it was scanned previously.
1616
*
1717
* @var string
1818
*/
1919
protected $outerHtml = null;
2020

2121
/**
22-
* Remembers what the text was if it was scaned previously.
22+
* Remembers what the text was if it was scanned previously.
2323
*
2424
* @var string
2525
*/
@@ -35,7 +35,9 @@ class HtmlNode extends ArrayNode {
3535

3636
/**
3737
* Sets up the tag of this node.
38-
*/
38+
*
39+
* @param $tag
40+
*/
3941
public function __construct($tag)
4042
{
4143
if ( ! $tag instanceof Tag)

src/PHPHtmlParser/Dom/MockNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/**
55
* This mock object is used solely for testing the abstract
66
* class Node with out any potential side effects caused
7-
* by testing a supperclass of Node.
7+
* by testing a supper class of Node.
88
*
99
* This object is not to be used for any other reason.
1010
*/

src/PHPHtmlParser/Dom/Tag.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function name()
6767
/**
6868
* Sets the tag to be self closing.
6969
*
70-
* @chainable
70+
* @return $this
7171
*/
7272
public function selfClosing()
7373
{
@@ -93,7 +93,8 @@ public function setEncoding(Encode $encode)
9393
/**
9494
* Sets the noise for this tag (if any)
9595
*
96-
* @chainable
96+
* @param $noise
97+
* @return $this
9798
*/
9899
public function noise($noise)
99100
{
@@ -106,7 +107,7 @@ public function noise($noise)
106107
*
107108
* @param string $key
108109
* @param mixed $value
109-
* @chainable
110+
* @return $this
110111
*/
111112
public function setAttribute($key, $value)
112113
{
@@ -127,7 +128,7 @@ public function setAttribute($key, $value)
127128
* Sets the attributes for this tag
128129
*
129130
* @param array $attr
130-
* @chainable
131+
* @return $this
131132
*/
132133
public function setAttributes(array $attr)
133134
{
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
namespace PHPHtmlParser\Exceptions;
3+
4+
final class EmptyCollectionException extends \Exception {}

0 commit comments

Comments
 (0)