Skip to content

Commit c292062

Browse files
committed
feat (parsing): select first scalar by default
1 parent 94b88a3 commit c292062

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Iodev/Whois/Helpers/GroupSelector.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,29 @@ public function getAll()
2626
}
2727

2828
/**
29+
* First item
2930
* @param mixed $default
3031
* @return mixed
3132
*/
32-
public function getFirst($default = null)
33+
public function getFirstItem($default = null)
3334
{
3435
return empty($this->items) ? $default : reset($this->items);
3536
}
3637

38+
/**
39+
* First non-array value
40+
* @param mixed $default
41+
* @return mixed
42+
*/
43+
public function getFirst($default = null)
44+
{
45+
$first = $this->getFirstItem();
46+
while (is_array($first)) {
47+
$first = count($first) > 0 ? reset($first) : null;
48+
}
49+
return $first !== null ? $first : $default;
50+
}
51+
3752
/**
3853
* @return $this
3954
*/

0 commit comments

Comments
 (0)