Skip to content

Commit e221d93

Browse files
author
Kirill Nesmeyanov
committed
Add first and last methods int nodes list
1 parent bd43c59 commit e221d93

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Node/NodeList.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ public function __construct(
1818
public array $items = [],
1919
) {}
2020

21+
/**
22+
* @return TNode|null
23+
*/
24+
public function first(): ?Node
25+
{
26+
return \reset($this->items) ?: null;
27+
}
28+
29+
/**
30+
* @return TNode|null
31+
*/
32+
public function last(): ?Node
33+
{
34+
return \end($this->items) ?: null;
35+
}
36+
2137
public function getIterator(): \Traversable
2238
{
2339
return new \ArrayIterator($this->items);

0 commit comments

Comments
 (0)