Skip to content

Commit e5fc286

Browse files
committed
feat: arr, str - add some new helper method
1 parent 2aa57a0 commit e5fc286

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/Arr/ArrayHelper.php

+14
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ public static function isAssoc(array $array): bool
8181
return array_keys($keys) !== $keys;
8282
}
8383

84+
/**
85+
* check is a list array
86+
*
87+
* @param array $arr
88+
*
89+
* @return bool
90+
*/
91+
public static function isList(array $arr): bool
92+
{
93+
$keys = array_keys($arr);
94+
95+
return array_keys($keys) === $keys;
96+
}
97+
8498
/**
8599
* @param mixed $array
86100
*

src/Str/StringHelper.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,25 @@ public static function shellQuote(string $arg): string
460460
return $arg;
461461
}
462462

463+
return self::textQuote($arg);
464+
}
465+
466+
/**
467+
* Quote text on exist ', ", SPACE
468+
*
469+
* @param string $text
470+
*
471+
* @return string
472+
*/
473+
public static function textQuote(string $text): string
474+
{
463475
$quote = '';
464-
if (str_contains($arg, '"')) {
476+
if (str_contains($text, '"')) {
465477
$quote = "'";
466-
} elseif ($arg === '' || str_contains($arg, "'") || str_contains($arg, ' ')) {
478+
} elseif ($text === '' || str_contains($text, "'") || str_contains($text, ' ')) {
467479
$quote = '"';
468480
}
469481

470-
return $quote ? "$quote$arg$quote" : $arg;
482+
return $quote ? "$quote$text$quote" : $text;
471483
}
472484
}

0 commit comments

Comments
 (0)