Skip to content

Commit c35b89f

Browse files
committed
Added "NodeList::findIndex()" method (Also affects "ArgumentsListNode", "AttributeArgumentsListNode", "AttributeGroupNode", "AttributeGroupsListNode", "CallableParametersListNode", "FieldsListNode", "ParametersListNode", and "TemplateArgumentsListNode")
1 parent 2dd0794 commit c35b89f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Node/NodeList.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ public function __construct(
2121
public array $items = [],
2222
) {}
2323

24+
/**
25+
* Returns the ordinal number (position) of an element {@see TNode} in
26+
* a node list, starting with index 0.
27+
*
28+
* Returns {@see null} if the element {@see TNode} does not belong
29+
* to the node list.
30+
*
31+
* @param TNode $node
32+
* @return int<0, max>|null
33+
*/
34+
public function findIndex(object $node): ?int
35+
{
36+
$index = \array_search($node, $this->items, true);
37+
38+
if (\is_int($index)) {
39+
return $index;
40+
}
41+
42+
return null;
43+
}
44+
2445
/**
2546
* @return TNode|null
2647
*/

0 commit comments

Comments
 (0)