33use Permafrost \PhpCodeSearch \Support \Arr ;
44use Permafrost \PhpCodeSearch \Support \Collections \Collection ;
55
6- if (! function_exists ('optional ' )) {
7- function optional ($ value )
6+ if (! function_exists ('opt ' )) {
7+ /**
8+ * "optional" helper function
9+ * @param $value
10+ * @return mixed|__anonymous@237
11+ */
12+ function opt ($ value )
813 {
914 if (! $ value ) {
1015 return new class {
@@ -20,12 +25,12 @@ public function __call($name, $arguments)
2025 };
2126 }
2227
23- return value ($ value );
28+ return val ($ value );
2429 }
2530}
2631
2732/** @codeCoverageIgnore */
28- if (! function_exists ('data_get ' )) {
33+ if (! function_exists ('get_data ' )) {
2934 /**
3035 * Get an item from an array or object using "dot" notation.
3136 *
@@ -34,7 +39,7 @@ public function __call($name, $arguments)
3439 * @param mixed $default
3540 * @return mixed
3641 */
37- function data_get ($ target , $ key , $ default = null )
42+ function get_data ($ target , $ key , $ default = null )
3843 {
3944 if (is_null ($ key )) {
4045 return $ target ;
@@ -53,13 +58,13 @@ function data_get($target, $key, $default = null)
5358 if ($ target instanceof Collection) {
5459 $ target = $ target ->all ();
5560 } elseif (! is_iterable ($ target )) {
56- return value ($ default );
61+ return val ($ default );
5762 }
5863
5964 $ result = [];
6065
6166 foreach ($ target as $ item ) {
62- $ result [] = data_get ($ item , $ key );
67+ $ result [] = get_data ($ item , $ key );
6368 }
6469
6570 return in_array ('* ' , $ key ) ? Arr::collapse ($ result ) : $ result ;
@@ -70,7 +75,7 @@ function data_get($target, $key, $default = null)
7075 } elseif (is_object ($ target ) && isset ($ target ->{$ segment })) {
7176 $ target = $ target ->{$ segment };
7277 } else {
73- return value ($ default );
78+ return val ($ default );
7479 }
7580 }
7681
@@ -79,21 +84,21 @@ function data_get($target, $key, $default = null)
7984}
8085
8186/** @codeCoverageIgnore */
82- if (! function_exists ('value ' )) {
87+ if (! function_exists ('val ' )) {
8388 /**
8489 * Return the default value of the given value.
8590 *
8691 * @param mixed $value
8792 * @return mixed
8893 */
89- function value ($ value , ...$ args )
94+ function val ($ value , ...$ args )
9095 {
9196 return $ value instanceof Closure ? $ value (...$ args ) : $ value ;
9297 }
9398}
9499
95- if (! function_exists ('collect ' )) {
96- function collect ($ items )
100+ if (! function_exists ('collection ' )) {
101+ function collection ($ items )
97102 {
98103 return new Collection ($ items );
99104 }
0 commit comments