Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

v9.29.0 changes #322

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Collect/Support/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
99 changes: 50 additions & 49 deletions tests/files/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<array-key, string> $needles
* @param string|iterable<string> $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;
}
Expand All @@ -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<array-key, string> $needles
* @param iterable<string> $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;
}
}
Expand All @@ -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<array-key, string> $needles
* @param string|iterable<string> $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;
}
Expand Down Expand Up @@ -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<string> $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
Expand Down Expand Up @@ -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<array-key, string> $replace
* @param iterable<string> $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);
Expand All @@ -813,23 +810,23 @@ public static function replaceArray($search, $replace, $subject)
/**
* Replace the given value in the given string.
*
* @param string|string[]|Enumerable<array-key, string> $search
* @param string|string[]|Enumerable<array-key, string> $replace
* @param string|string[]|Enumerable<array-key, string> $subject
* @param string|iterable<string> $search
* @param string|iterable<string> $replace
* @param string|iterable<string> $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);
Expand Down Expand Up @@ -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<array-key, string> $search
* @param string|iterable<string> $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
Expand Down Expand Up @@ -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<array-key, string> $needles
* @param string|iterable<string> $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;
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
46 changes: 19 additions & 27 deletions tests/files/Support/Stringable.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function camel()
/**
* Determine if a given string contains a given substring.
*
* @param string|string[] $needles
* @param string|iterable<string> $needles
* @return bool
*/
public function contains($needles)
Expand All @@ -177,10 +177,10 @@ public function contains($needles)
/**
* Determine if a given string contains all array values.
*
* @param array $needles
* @param iterable<string> $needles
* @return bool
*/
public function containsAll(array $needles)
public function containsAll($needles)
{
return Str::containsAll($this->value, $needles);
}
Expand All @@ -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<string> $needles
* @return bool
*/
public function endsWith($needles)
Expand Down Expand Up @@ -279,7 +279,7 @@ public function finish($cap)
/**
* Determine if a given string matches a given pattern.
*
* @param string|array $pattern
* @param string|iterable<string> $pattern
* @return bool
*/
public function is($pattern)
Expand Down Expand Up @@ -576,31 +576,23 @@ public function repeat(int $times)
/**
* Replace the given value in the given string.
*
* @param string|string[]|Enumerable<array-key, string> $search
* @param string|string[]|Enumerable<array-key, string> $replace
* @param string|iterable<string> $search
* @param string|iterable<string> $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<string> $replace
* @return static
*/
public function replaceArray($search, array $replace)
public function replaceArray($search, $replace)
{
return new static(Str::replaceArray($search, $replace, $this->value));
}
Expand Down Expand Up @@ -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<string> $needles
* @return bool
*/
public function startsWith($needles)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<string> $needles
* @param callable $callback
* @param callable|null $default
* @return static
Expand All @@ -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<string> $needles
* @param callable $callback
* @param callable|null $default
* @return static
Expand Down Expand Up @@ -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<string> $needles
* @param callable $callback
* @param callable|null $default
* @return static
Expand Down Expand Up @@ -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<string> $pattern
* @param callable $callback
* @param callable|null $default
* @return static
Expand Down Expand Up @@ -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<string> $needles
* @param callable $callback
* @param callable|null $default
* @return static
Expand Down
2 changes: 1 addition & 1 deletion upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down