diff --git a/src/Collect/Support/LazyCollection.php b/src/Collect/Support/LazyCollection.php index cc022ca..1142492 100644 --- a/src/Collect/Support/LazyCollection.php +++ b/src/Collect/Support/LazyCollection.php @@ -398,7 +398,7 @@ public function except($keys) /** * Run a filter over each of the items. * - * @param (callable(TValue): bool)|null $callback + * @param (callable(TValue, TKey): bool)|null $callback * @return static */ public function filter(callable $callback = null) diff --git a/tests/files/Support/Str.php b/tests/files/Support/Str.php index 7c1ffb9..aa6b5c5 100644 --- a/tests/files/Support/Str.php +++ b/tests/files/Support/Str.php @@ -14,6 +14,7 @@ use Ramsey\Uuid\Generator\CombGenerator; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidFactory; +use Traversable; use voku\helper\ASCII; class Str @@ -218,22 +219,25 @@ public static function camel($value) * Determine if a given string contains a given substring. * * @param string $haystack - * @param string|string[]|Enumerable $needles + * @param string|iterable $needles * @param bool $ignoreCase * @return bool */ public static function contains($haystack, $needles, $ignoreCase = false) { - if ($needles instanceof Enumerable) { - $needles = $needles->toArray(); - } - if ($ignoreCase) { $haystack = mb_strtolower($haystack); - $needles = array_map('mb_strtolower', (array) $needles); } - foreach ((array) $needles as $needle) { + if (! is_iterable($needles)) { + $needles = (array) $needles; + } + + foreach ($needles as $needle) { + if ($ignoreCase) { + $needle = mb_strtolower($needle); + } + if ($needle !== '' && str_contains($haystack, $needle)) { return true; } @@ -246,23 +250,14 @@ public static function contains($haystack, $needles, $ignoreCase = false) * Determine if a given string contains all array values. * * @param string $haystack - * @param string[]|Enumerable $needles + * @param iterable $needles * @param bool $ignoreCase * @return bool */ public static function containsAll($haystack, $needles, $ignoreCase = false) { - if ($needles instanceof Enumerable) { - $needles = $needles->toArray(); - } - - if ($ignoreCase) { - $haystack = mb_strtolower($haystack); - $needles = array_map('mb_strtolower', $needles); - } - foreach ($needles as $needle) { - if (! static::contains($haystack, $needle)) { + if (! static::contains($haystack, $needle, $ignoreCase)) { return false; } } @@ -274,12 +269,16 @@ public static function containsAll($haystack, $needles, $ignoreCase = false) * Determine if a given string ends with a given substring. * * @param string $haystack - * @param string|string[]|Enumerable $needles + * @param string|iterable $needles * @return bool */ public static function endsWith($haystack, $needles) { - foreach ((array) $needles as $needle) { + if (! is_iterable($needles)) { + $needles = (array) $needles; + } + + foreach ($needles as $needle) { if ((string) $needle !== '' && str_ends_with($haystack, $needle)) { return true; } @@ -341,21 +340,19 @@ public static function finish($value, $cap) /** * Determine if a given string matches a given pattern. * - * @param string|array $pattern + * @param string|iterable $pattern * @param string $value * @return bool */ public static function is($pattern, $value) { - $patterns = Arr::wrap($pattern); - $value = (string) $value; - if (empty($patterns)) { - return false; + if (! is_iterable($pattern)) { + $pattern = [$pattern]; } - foreach ($patterns as $pattern) { + foreach ($pattern as $pattern) { $pattern = (string) $pattern; // If the given value is an exact match we can of course return true right @@ -789,14 +786,14 @@ public static function repeat(string $string, int $times) * Replace a given value in the string sequentially with an array. * * @param string $search - * @param string[]|Enumerable $replace + * @param iterable $replace * @param string $subject * @return string */ public static function replaceArray($search, $replace, $subject) { - if ($replace instanceof Enumerable) { - $replace = $replace->toArray(); + if ($replace instanceof Traversable) { + $replace = collect($replace)->all(); } $segments = explode($search, $subject); @@ -813,23 +810,23 @@ public static function replaceArray($search, $replace, $subject) /** * Replace the given value in the given string. * - * @param string|string[]|Enumerable $search - * @param string|string[]|Enumerable $replace - * @param string|string[]|Enumerable $subject + * @param string|iterable $search + * @param string|iterable $replace + * @param string|iterable $subject * @return string */ public static function replace($search, $replace, $subject) { - if ($search instanceof Enumerable) { - $search = $search->toArray(); + if ($search instanceof Traversable) { + $search = collect($search)->all(); } - if ($replace instanceof Enumerable) { - $replace = $replace->toArray(); + if ($replace instanceof Traversable) { + $replace = collect($replace)->all(); } - if ($subject instanceof Enumerable) { - $subject = $subject->toArray(); + if ($subject instanceof Traversable) { + $subject = collect($subject)->all(); } return str_replace($search, $replace, $subject); @@ -886,15 +883,15 @@ public static function replaceLast($search, $replace, $subject) /** * Remove any occurrence of the given string in the subject. * - * @param string|string[]|Enumerable $search + * @param string|iterable $search * @param string $subject * @param bool $caseSensitive * @return string */ public static function remove($search, $subject, $caseSensitive = true) { - if ($search instanceof Enumerable) { - $search = $search->toArray(); + if ($search instanceof Traversable) { + $search = collect($search)->all(); } $subject = $caseSensitive @@ -1049,12 +1046,16 @@ public static function squish($value) * Determine if a given string starts with a given substring. * * @param string $haystack - * @param string|string[]|Enumerable $needles + * @param string|iterable $needles * @return bool */ public static function startsWith($haystack, $needles) { - foreach ((array) $needles as $needle) { + if (! is_iterable($needles)) { + $needles = [$needles]; + } + + foreach ($needles as $needle) { if ((string) $needle !== '' && str_starts_with($haystack, $needle)) { return true; } @@ -1118,11 +1119,11 @@ public static function substrCount($haystack, $needle, $offset = 0, $length = nu /** * Replace text within a portion of a string. * - * @param string|array $string - * @param string|array $replace - * @param array|int $offset - * @param array|int|null $length - * @return string|array + * @param string|string[] $string + * @param string|string[] $replace + * @param int|int[] $offset + * @param int|int[]|null $length + * @return string|string[] */ public static function substrReplace($string, $replace, $offset = 0, $length = null) { @@ -1171,7 +1172,7 @@ public static function ucfirst($string) * Split a string into pieces by uppercase characters. * * @param string $string - * @return array + * @return string[] */ public static function ucsplit($string) { diff --git a/tests/files/Support/Stringable.php b/tests/files/Support/Stringable.php index 83e6e31..ddfdd50 100644 --- a/tests/files/Support/Stringable.php +++ b/tests/files/Support/Stringable.php @@ -166,7 +166,7 @@ public function camel() /** * Determine if a given string contains a given substring. * - * @param string|string[] $needles + * @param string|iterable $needles * @return bool */ public function contains($needles) @@ -177,10 +177,10 @@ public function contains($needles) /** * Determine if a given string contains all array values. * - * @param array $needles + * @param iterable $needles * @return bool */ - public function containsAll(array $needles) + public function containsAll($needles) { return Str::containsAll($this->value, $needles); } @@ -199,7 +199,7 @@ public function dirname($levels = 1) /** * Determine if a given string ends with a given substring. * - * @param string|string[] $needles + * @param string|iterable $needles * @return bool */ public function endsWith($needles) @@ -279,7 +279,7 @@ public function finish($cap) /** * Determine if a given string matches a given pattern. * - * @param string|array $pattern + * @param string|iterable $pattern * @return bool */ public function is($pattern) @@ -576,31 +576,23 @@ public function repeat(int $times) /** * Replace the given value in the given string. * - * @param string|string[]|Enumerable $search - * @param string|string[]|Enumerable $replace + * @param string|iterable $search + * @param string|iterable $replace * @return static */ public function replace($search, $replace) { - if ($search instanceof Enumerable) { - $search = $search->toArray(); - } - - if ($replace instanceof Enumerable) { - $replace = $replace->toArray(); - } - - return new static(str_replace($search, $replace, $this->value)); + return new static(Str::replace($search, $replace, $this->value)); } /** * Replace a given value in the string sequentially with an array. * * @param string $search - * @param array $replace + * @param iterable $replace * @return static */ - public function replaceArray($search, array $replace) + public function replaceArray($search, $replace) { return new static(Str::replaceArray($search, $replace, $this->value)); } @@ -755,7 +747,7 @@ public function snake($delimiter = '_') /** * Determine if a given string starts with a given substring. * - * @param string|string[] $needles + * @param string|iterable $needles * @return bool */ public function startsWith($needles) @@ -801,9 +793,9 @@ public function substrCount($needle, $offset = null, $length = null) /** * Replace text within a portion of a string. * - * @param string|array $replace - * @param array|int $offset - * @param array|int|null $length + * @param string|string[] $replace + * @param int|int[] $offset + * @param int|int[]|null $length * @return static */ public function substrReplace($replace, $offset = 0, $length = null) @@ -888,7 +880,7 @@ public function ucsplit() /** * Execute the given callback if the string contains a given substring. * - * @param string|string[] $needles + * @param string|iterable $needles * @param callable $callback * @param callable|null $default * @return static @@ -901,7 +893,7 @@ public function whenContains($needles, $callback, $default = null) /** * Execute the given callback if the string contains all array values. * - * @param array $needles + * @param iterable $needles * @param callable $callback * @param callable|null $default * @return static @@ -938,7 +930,7 @@ public function whenNotEmpty($callback, $default = null) /** * Execute the given callback if the string ends with a given substring. * - * @param string|string[] $needles + * @param string|iterable $needles * @param callable $callback * @param callable|null $default * @return static @@ -977,7 +969,7 @@ public function whenNotExactly($value, $callback, $default = null) /** * Execute the given callback if the string matches a given pattern. * - * @param string|array $pattern + * @param string|iterable $pattern * @param callable $callback * @param callable|null $default * @return static @@ -1014,7 +1006,7 @@ public function whenIsUuid($callback, $default = null) /** * Execute the given callback if the string starts with a given substring. * - * @param string|string[] $needles + * @param string|iterable $needles * @param callable $callback * @param callable|null $default * @return static diff --git a/upgrade.sh b/upgrade.sh index 9782e88..5fb0030 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -381,7 +381,7 @@ function getCurrentVersionFromGitHub() echo Getting current version from $repository... if [ -z "$requestedVersion" ]; then - collectionVersion=$(git ls-remote $repository --tags v9.28\* | grep tags/ | grep -v {} | cut -d \/ -f 3 | cut -d v -f 2 | grep -v RC | grep -vi beta | sort -t. -k 1,1n -k 2,2n -k 3,3n| tail -1) + collectionVersion=$(git ls-remote $repository --tags v9.29\* | grep tags/ | grep -v {} | cut -d \/ -f 3 | cut -d v -f 2 | grep -v RC | grep -vi beta | sort -t. -k 1,1n -k 2,2n -k 3,3n| tail -1) else collectionVersion=$requestedVersion fi