From cef1dc13c07c85a832dcb53cff2be90e3f0c59d2 Mon Sep 17 00:00:00 2001 From: luke Date: Wed, 17 Mar 2021 20:27:03 +0000 Subject: [PATCH 1/5] Adds `Str::remove` and `Str::of('foobar')->remove` methods --- src/Illuminate/Support/Str.php | 12 ++++++++++++ src/Illuminate/Support/Stringable.php | 11 +++++++++++ tests/Support/SupportStrTest.php | 8 ++++++++ tests/Support/SupportStringableTest.php | 9 +++++++++ 4 files changed, 40 insertions(+) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index c1ea0017b782..e2d3fb4bc530 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -491,6 +491,18 @@ public static function random($length = 16) return $string; } + /** + * Remove any occurrence of the given string in the subject. + * + * @param string $search + * @param string $subject + * @return string + */ + public static function remove($search, $subject) + { + return str_replace($search, "", $subject); + } + /** * Replace a given value in the string sequentially with an array. * diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index d834260e11cf..c66d3044dc3a 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -467,6 +467,17 @@ public function prepend(...$values) return new static(implode('', $values).$this->value); } + /** + * Remove any occurrence of the given string in the subject. + * + * @param string $search + * @return static + */ + public function remove($search) + { + return new static(Str::remove($search, $this->value)); + } + /** * Replace the given value in the given string. * diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index f873e3bd934d..81bb6ccf0903 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -365,6 +365,14 @@ public function testReplaceLast() $this->assertSame('Malmö Jönköping', Str::replaceLast('', 'yyy', 'Malmö Jönköping')); } + public function testRemove() + { + $this->assertSame("Fbar", Str::remove('o', 'Foobar')); + $this->assertSame("Foo", Str::remove('bar', 'Foobar')); + $this->assertSame("oobar", Str::remove('F', 'Foobar')); + $this->assertSame("Foobar", Str::remove('f', 'Foobar')); + } + public function testSnake() { $this->assertSame('laravel_p_h_p_framework', Str::snake('LaravelPHPFramework')); diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index d6c010fd20fd..6477f2b31a1f 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -3,6 +3,7 @@ namespace Illuminate\Tests\Support; use Illuminate\Support\Collection; +use Illuminate\Support\Str; use Illuminate\Support\Stringable; use PHPUnit\Framework\TestCase; @@ -452,6 +453,14 @@ public function testReplaceLast() $this->assertSame('Malmö Jönköping', (string) $this->stringable('Malmö Jönköping')->replaceLast('', 'yyy')); } + public function testRemove() + { + $this->assertSame("Fbar", (string) $this->stringable('Foobar')->remove('o')); + $this->assertSame("Foo", (string) $this->stringable('Foobar')->remove('bar')); + $this->assertSame("oobar", (string) $this->stringable('Foobar')->remove('F')); + $this->assertSame("Foobar", (string) $this->stringable('Foobar')->remove('f')); + } + public function testSnake() { $this->assertSame('laravel_p_h_p_framework', (string) $this->stringable('LaravelPHPFramework')->snake()); From 1f64f7aaf351a6a87a1b2db95a88fb94206ce9c5 Mon Sep 17 00:00:00 2001 From: luke Date: Wed, 17 Mar 2021 20:50:59 +0000 Subject: [PATCH 2/5] Adds case insensitivity support. --- src/Illuminate/Support/Str.php | 9 ++++++--- src/Illuminate/Support/Stringable.php | 7 ++++--- tests/Support/SupportStrTest.php | 5 +++++ tests/Support/SupportStringableTest.php | 5 +++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index e2d3fb4bc530..ff923d46419e 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -494,13 +494,16 @@ public static function random($length = 16) /** * Remove any occurrence of the given string in the subject. * - * @param string $search + * @param string|array $search * @param string $subject + * @param bool $caseSensitive * @return string */ - public static function remove($search, $subject) + public static function remove($search, $subject, $caseSensitive = true) { - return str_replace($search, "", $subject); + $search = is_array($search) ? implode("|", $search) : $search; + $regex = $caseSensitive ? "/$search/" : "/$search/i"; + return preg_replace($regex, "", $subject); } /** diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index c66d3044dc3a..29e62b89eca6 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -470,12 +470,13 @@ public function prepend(...$values) /** * Remove any occurrence of the given string in the subject. * - * @param string $search + * @param string|array $search + * @param bool $caseSensitive * @return static */ - public function remove($search) + public function remove($search, $caseSensitive = true) { - return new static(Str::remove($search, $this->value)); + return new static(Str::remove($search, $this->value, $caseSensitive)); } /** diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index 81bb6ccf0903..d6a26b48607e 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -371,6 +371,11 @@ public function testRemove() $this->assertSame("Foo", Str::remove('bar', 'Foobar')); $this->assertSame("oobar", Str::remove('F', 'Foobar')); $this->assertSame("Foobar", Str::remove('f', 'Foobar')); + $this->assertSame("oobar", Str::remove('f', 'Foobar', false)); + + $this->assertSame("Fbr", Str::remove(["o", "a"], 'Foobar')); + $this->assertSame("Fooar", Str::remove(["f", "b"], 'Foobar')); + $this->assertSame("ooar", Str::remove(["f", "b"], 'Foobar', false)); } public function testSnake() diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index 6477f2b31a1f..89fe1fb9c000 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -459,6 +459,11 @@ public function testRemove() $this->assertSame("Foo", (string) $this->stringable('Foobar')->remove('bar')); $this->assertSame("oobar", (string) $this->stringable('Foobar')->remove('F')); $this->assertSame("Foobar", (string) $this->stringable('Foobar')->remove('f')); + $this->assertSame("oobar", (string) $this->stringable('Foobar')->remove('f', false)); + + $this->assertSame("Fbr", (string) $this->stringable('Foobar')->remove(["o", "a"])); + $this->assertSame("Fooar", (string) $this->stringable('Foobar')->remove(["f", "b"])); + $this->assertSame("ooar", (string) $this->stringable('Foobar')->remove(["f", "b"], false)); } public function testSnake() From e87398a594b2f93d10f51036aa16f4c81077035f Mon Sep 17 00:00:00 2001 From: luke Date: Wed, 17 Mar 2021 21:03:50 +0000 Subject: [PATCH 3/5] Adds regex case insensitivity. --- src/Illuminate/Support/Str.php | 473 ++++++++++++------------ tests/Support/SupportStrTest.php | 1 + tests/Support/SupportStringableTest.php | 1 + 3 files changed, 246 insertions(+), 229 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index ff923d46419e..17e5e29e501c 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -45,7 +45,7 @@ class Str /** * Get a new stringable object from the given string. * - * @param string $string + * @param string $string * @return \Illuminate\Support\Stringable */ public static function of($string) @@ -53,23 +53,11 @@ public static function of($string) return new Stringable($string); } - /** - * Return the remainder of a string after the first occurrence of a given value. - * - * @param string $subject - * @param string $search - * @return string - */ - public static function after($subject, $search) - { - return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0]; - } - /** * Return the remainder of a string after the last occurrence of a given value. * - * @param string $subject - * @param string $search + * @param string $subject + * @param string $search * @return string */ public static function afterLast($subject, $search) @@ -78,7 +66,7 @@ public static function afterLast($subject, $search) return $subject; } - $position = strrpos($subject, (string) $search); + $position = strrpos($subject, (string)$search); if ($position === false) { return $subject; @@ -88,40 +76,45 @@ public static function afterLast($subject, $search) } /** - * Transliterate a UTF-8 value to ASCII. + * Get the portion of a string before the first occurrence of a given value. * - * @param string $value - * @param string $language + * @param string $subject + * @param string $search * @return string */ - public static function ascii($value, $language = 'en') + public static function before($subject, $search) { - return ASCII::to_ascii((string) $value, $language); + if ($search === '') { + return $subject; + } + + $result = strstr($subject, (string)$search, true); + + return $result === false ? $subject : $result; } /** - * Get the portion of a string before the first occurrence of a given value. + * Get the portion of a string between two given values. * - * @param string $subject - * @param string $search + * @param string $subject + * @param string $from + * @param string $to * @return string */ - public static function before($subject, $search) + public static function between($subject, $from, $to) { - if ($search === '') { + if ($from === '' || $to === '') { return $subject; } - $result = strstr($subject, (string) $search, true); - - return $result === false ? $subject : $result; + return static::beforeLast(static::after($subject, $from), $to); } /** * Get the portion of a string before the last occurrence of a given value. * - * @param string $subject - * @param string $search + * @param string $subject + * @param string $search * @return string */ public static function beforeLast($subject, $search) @@ -140,26 +133,34 @@ public static function beforeLast($subject, $search) } /** - * Get the portion of a string between two given values. + * Returns the portion of the string specified by the start and length parameters. * - * @param string $subject - * @param string $from - * @param string $to + * @param string $string + * @param int $start + * @param int|null $length * @return string */ - public static function between($subject, $from, $to) + public static function substr($string, $start, $length = null) { - if ($from === '' || $to === '') { - return $subject; - } + return mb_substr($string, $start, $length, 'UTF-8'); + } - return static::beforeLast(static::after($subject, $from), $to); + /** + * Return the remainder of a string after the first occurrence of a given value. + * + * @param string $subject + * @param string $search + * @return string + */ + public static function after($subject, $search) + { + return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0]; } /** * Convert a value to camel case. * - * @param string $value + * @param string $value * @return string */ public static function camel($value) @@ -172,34 +173,35 @@ public static function camel($value) } /** - * Determine if a given string contains a given substring. + * Convert a value to studly caps case. * - * @param string $haystack - * @param string|string[] $needles - * @return bool + * @param string $value + * @return string */ - public static function contains($haystack, $needles) + public static function studly($value) { - foreach ((array) $needles as $needle) { - if ($needle !== '' && mb_strpos($haystack, $needle) !== false) { - return true; - } + $key = $value; + + if (isset(static::$studlyCache[$key])) { + return static::$studlyCache[$key]; } - return false; + $value = ucwords(str_replace(['-', '_'], ' ', $value)); + + return static::$studlyCache[$key] = str_replace(' ', '', $value); } /** * Determine if a given string contains all array values. * - * @param string $haystack - * @param string[] $needles + * @param string $haystack + * @param string[] $needles * @return bool */ public static function containsAll($haystack, array $needles) { foreach ($needles as $needle) { - if (! static::contains($haystack, $needle)) { + if (!static::contains($haystack, $needle)) { return false; } } @@ -207,17 +209,35 @@ public static function containsAll($haystack, array $needles) return true; } + /** + * Determine if a given string contains a given substring. + * + * @param string $haystack + * @param string|string[] $needles + * @return bool + */ + public static function contains($haystack, $needles) + { + foreach ((array)$needles as $needle) { + if ($needle !== '' && mb_strpos($haystack, $needle) !== false) { + return true; + } + } + + return false; + } + /** * Determine if a given string ends with a given substring. * - * @param string $haystack - * @param string|string[] $needles + * @param string $haystack + * @param string|string[] $needles * @return bool */ public static function endsWith($haystack, $needles) { - foreach ((array) $needles as $needle) { - if ($needle !== '' && substr($haystack, -strlen($needle)) === (string) $needle) { + foreach ((array)$needles as $needle) { + if ($needle !== '' && substr($haystack, -strlen($needle)) === (string)$needle) { return true; } } @@ -228,22 +248,22 @@ public static function endsWith($haystack, $needles) /** * Cap a string with a single instance of a given value. * - * @param string $value - * @param string $cap + * @param string $value + * @param string $cap * @return string */ public static function finish($value, $cap) { $quoted = preg_quote($cap, '/'); - return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap; + return preg_replace('/(?:' . $quoted . ')+$/u', '', $value) . $cap; } /** * Determine if a given string matches a given pattern. * - * @param string|array $pattern - * @param string $value + * @param string|array $pattern + * @param string $value * @return bool */ public static function is($pattern, $value) @@ -269,7 +289,7 @@ public static function is($pattern, $value) // pattern such as "library/*", making any string check convenient. $pattern = str_replace('\*', '.*', $pattern); - if (preg_match('#^'.$pattern.'\z#u', $value) === 1) { + if (preg_match('#^' . $pattern . '\z#u', $value) === 1) { return true; } } @@ -280,23 +300,23 @@ public static function is($pattern, $value) /** * Determine if a given string is 7 bit ASCII. * - * @param string $value + * @param string $value * @return bool */ public static function isAscii($value) { - return ASCII::is_ascii((string) $value); + return ASCII::is_ascii((string)$value); } /** * Determine if a given string is a valid UUID. * - * @param string $value + * @param string $value * @return bool */ public static function isUuid($value) { - if (! is_string($value)) { + if (!is_string($value)) { return false; } @@ -306,7 +326,7 @@ public static function isUuid($value) /** * Convert a string to kebab case. * - * @param string $value + * @param string $value * @return string */ public static function kebab($value) @@ -315,27 +335,46 @@ public static function kebab($value) } /** - * Return the length of the given string. + * Convert a string to snake case. * - * @param string $value - * @param string|null $encoding - * @return int + * @param string $value + * @param string $delimiter + * @return string */ - public static function length($value, $encoding = null) + public static function snake($value, $delimiter = '_') { - if ($encoding) { - return mb_strlen($value, $encoding); + $key = $value; + + if (isset(static::$snakeCache[$key][$delimiter])) { + return static::$snakeCache[$key][$delimiter]; } - return mb_strlen($value); + if (!ctype_lower($value)) { + $value = preg_replace('/\s+/u', '', ucwords($value)); + + $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value)); + } + + return static::$snakeCache[$key][$delimiter] = $value; + } + + /** + * Convert the given string to lower-case. + * + * @param string $value + * @return string + */ + public static function lower($value) + { + return mb_strtolower($value, 'UTF-8'); } /** * Limit the number of characters in a string. * - * @param string $value - * @param int $limit - * @param string $end + * @param string $value + * @param int $limit + * @param string $end * @return string */ public static function limit($value, $limit = 100, $end = '...') @@ -344,44 +383,49 @@ public static function limit($value, $limit = 100, $end = '...') return $value; } - return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end; + return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end; } /** - * Convert the given string to lower-case. + * Limit the number of words in a string. * - * @param string $value + * @param string $value + * @param int $words + * @param string $end * @return string */ - public static function lower($value) + public static function words($value, $words = 100, $end = '...') { - return mb_strtolower($value, 'UTF-8'); + preg_match('/^\s*+(?:\S++\s*+){1,' . $words . '}/u', $value, $matches); + + if (!isset($matches[0]) || static::length($value) === static::length($matches[0])) { + return $value; + } + + return rtrim($matches[0]) . $end; } /** - * Limit the number of words in a string. + * Return the length of the given string. * - * @param string $value - * @param int $words - * @param string $end - * @return string + * @param string $value + * @param string|null $encoding + * @return int */ - public static function words($value, $words = 100, $end = '...') + public static function length($value, $encoding = null) { - preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches); - - if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) { - return $value; + if ($encoding) { + return mb_strlen($value, $encoding); } - return rtrim($matches[0]).$end; + return mb_strlen($value); } /** * Converts GitHub flavored Markdown into HTML. * - * @param string $string - * @param array $options + * @param string $string + * @param array $options * @return string */ public static function markdown($string, array $options = []) @@ -394,9 +438,9 @@ public static function markdown($string, array $options = []) /** * Pad both sides of a string with another. * - * @param string $value - * @param int $length - * @param string $pad + * @param string $value + * @param int $length + * @param string $pad * @return string */ public static function padBoth($value, $length, $pad = ' ') @@ -407,9 +451,9 @@ public static function padBoth($value, $length, $pad = ' ') /** * Pad the left side of a string with another. * - * @param string $value - * @param int $length - * @param string $pad + * @param string $value + * @param int $length + * @param string $pad * @return string */ public static function padLeft($value, $length, $pad = ' ') @@ -420,9 +464,9 @@ public static function padLeft($value, $length, $pad = ' ') /** * Pad the right side of a string with another. * - * @param string $value - * @param int $length - * @param string $pad + * @param string $value + * @param int $length + * @param string $pad * @return string */ public static function padRight($value, $length, $pad = ' ') @@ -433,8 +477,8 @@ public static function padRight($value, $length, $pad = ' ') /** * Parse a Class[@]method style callback into class and method. * - * @param string $callback - * @param string|null $default + * @param string $callback + * @param string|null $default * @return array */ public static function parseCallback($callback, $default = null) @@ -443,37 +487,37 @@ public static function parseCallback($callback, $default = null) } /** - * Get the plural form of an English word. + * Pluralize the last word of an English, studly caps case string. * - * @param string $value - * @param int $count + * @param string $value + * @param int $count * @return string */ - public static function plural($value, $count = 2) + public static function pluralStudly($value, $count = 2) { - return Pluralizer::plural($value, $count); + $parts = preg_split('/(.)(?=[A-Z])/u', $value, -1, PREG_SPLIT_DELIM_CAPTURE); + + $lastWord = array_pop($parts); + + return implode('', $parts) . self::plural($lastWord, $count); } /** - * Pluralize the last word of an English, studly caps case string. + * Get the plural form of an English word. * - * @param string $value - * @param int $count + * @param string $value + * @param int $count * @return string */ - public static function pluralStudly($value, $count = 2) + public static function plural($value, $count = 2) { - $parts = preg_split('/(.)(?=[A-Z])/u', $value, -1, PREG_SPLIT_DELIM_CAPTURE); - - $lastWord = array_pop($parts); - - return implode('', $parts).self::plural($lastWord, $count); + return Pluralizer::plural($value, $count); } /** * Generate a more truly "random" alpha-numeric string. * - * @param int $length + * @param int $length * @return string */ public static function random($length = 16) @@ -501,17 +545,28 @@ public static function random($length = 16) */ public static function remove($search, $subject, $caseSensitive = true) { - $search = is_array($search) ? implode("|", $search) : $search; - $regex = $caseSensitive ? "/$search/" : "/$search/i"; + $regexSafeSearches = array_map( + function ($search) { + return preg_quote($search); + }, + is_array($search) ? $search : [$search] + ); + + $regex = "/" . implode("|", $regexSafeSearches) . "/"; + + if (!$caseSensitive) { + $regex .= "i"; + } + return preg_replace($regex, "", $subject); } /** * Replace a given value in the string sequentially with an array. * - * @param string $search - * @param array $replace - * @param string $subject + * @param string $search + * @param array $replace + * @param string $subject * @return string */ public static function replaceArray($search, array $replace, $subject) @@ -521,7 +576,7 @@ public static function replaceArray($search, array $replace, $subject) $result = array_shift($segments); foreach ($segments as $segment) { - $result .= (array_shift($replace) ?? $search).$segment; + $result .= (array_shift($replace) ?? $search) . $segment; } return $result; @@ -530,9 +585,9 @@ public static function replaceArray($search, array $replace, $subject) /** * Replace the first occurrence of a given value in the string. * - * @param string $search - * @param string $replace - * @param string $subject + * @param string $search + * @param string $replace + * @param string $subject * @return string */ public static function replaceFirst($search, $replace, $subject) @@ -553,9 +608,9 @@ public static function replaceFirst($search, $replace, $subject) /** * Replace the last occurrence of a given value in the string. * - * @param string $search - * @param string $replace - * @param string $subject + * @param string $search + * @param string $replace + * @param string $subject * @return string */ public static function replaceLast($search, $replace, $subject) @@ -576,32 +631,21 @@ public static function replaceLast($search, $replace, $subject) /** * Begin a string with a single instance of a given value. * - * @param string $value - * @param string $prefix + * @param string $value + * @param string $prefix * @return string */ public static function start($value, $prefix) { $quoted = preg_quote($prefix, '/'); - return $prefix.preg_replace('/^(?:'.$quoted.')+/u', '', $value); - } - - /** - * Convert the given string to upper-case. - * - * @param string $value - * @return string - */ - public static function upper($value) - { - return mb_strtoupper($value, 'UTF-8'); + return $prefix . preg_replace('/^(?:' . $quoted . ')+/u', '', $value); } /** * Convert the given string to title case. * - * @param string $value + * @param string $value * @return string */ public static function title($value) @@ -612,7 +656,7 @@ public static function title($value) /** * Get the singular form of an English word. * - * @param string $value + * @param string $value * @return string */ public static function singular($value) @@ -623,9 +667,9 @@ public static function singular($value) /** * Generate a URL friendly "slug" from a given string. * - * @param string $title - * @param string $separator - * @param string|null $language + * @param string $title + * @param string $separator + * @param string|null $language * @return string */ public static function slug($title, $separator = '-', $language = 'en') @@ -635,55 +679,43 @@ public static function slug($title, $separator = '-', $language = 'en') // Convert all dashes/underscores into separator $flip = $separator === '-' ? '_' : '-'; - $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); + $title = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $title); // Replace @ with the word 'at' - $title = str_replace('@', $separator.'at'.$separator, $title); + $title = str_replace('@', $separator . 'at' . $separator, $title); // Remove all characters that are not the separator, letters, numbers, or whitespace. - $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', static::lower($title)); + $title = preg_replace('![^' . preg_quote($separator) . '\pL\pN\s]+!u', '', static::lower($title)); // Replace all separator characters and whitespace by a single separator - $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); + $title = preg_replace('![' . preg_quote($separator) . '\s]+!u', $separator, $title); return trim($title, $separator); } /** - * Convert a string to snake case. + * Transliterate a UTF-8 value to ASCII. * - * @param string $value - * @param string $delimiter + * @param string $value + * @param string $language * @return string */ - public static function snake($value, $delimiter = '_') + public static function ascii($value, $language = 'en') { - $key = $value; - - if (isset(static::$snakeCache[$key][$delimiter])) { - return static::$snakeCache[$key][$delimiter]; - } - - if (! ctype_lower($value)) { - $value = preg_replace('/\s+/u', '', ucwords($value)); - - $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value)); - } - - return static::$snakeCache[$key][$delimiter] = $value; + return ASCII::to_ascii((string)$value, $language); } /** * Determine if a given string starts with a given substring. * - * @param string $haystack - * @param string|string[] $needles + * @param string $haystack + * @param string|string[] $needles * @return bool */ public static function startsWith($haystack, $needles) { - foreach ((array) $needles as $needle) { - if ((string) $needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0) { + foreach ((array)$needles as $needle) { + if ((string)$needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0) { return true; } } @@ -691,50 +723,18 @@ public static function startsWith($haystack, $needles) return false; } - /** - * Convert a value to studly caps case. - * - * @param string $value - * @return string - */ - public static function studly($value) - { - $key = $value; - - if (isset(static::$studlyCache[$key])) { - return static::$studlyCache[$key]; - } - - $value = ucwords(str_replace(['-', '_'], ' ', $value)); - - return static::$studlyCache[$key] = str_replace(' ', '', $value); - } - - /** - * Returns the portion of the string specified by the start and length parameters. - * - * @param string $string - * @param int $start - * @param int|null $length - * @return string - */ - public static function substr($string, $start, $length = null) - { - return mb_substr($string, $start, $length, 'UTF-8'); - } - /** * Returns the number of substring occurrences. * - * @param string $haystack - * @param string $needle - * @param int $offset - * @param int|null $length + * @param string $haystack + * @param string $needle + * @param int $offset + * @param int|null $length * @return int */ public static function substrCount($haystack, $needle, $offset = 0, $length = null) { - if (! is_null($length)) { + if (!is_null($length)) { return substr_count($haystack, $needle, $offset, $length); } else { return substr_count($haystack, $needle, $offset); @@ -744,12 +744,23 @@ public static function substrCount($haystack, $needle, $offset = 0, $length = nu /** * Make a string's first character uppercase. * - * @param string $string + * @param string $string * @return string */ public static function ucfirst($string) { - return static::upper(static::substr($string, 0, 1)).static::substr($string, 1); + return static::upper(static::substr($string, 0, 1)) . static::substr($string, 1); + } + + /** + * Convert the given string to upper-case. + * + * @param string $value + * @return string + */ + public static function upper($value) + { + return mb_strtoupper($value, 'UTF-8'); } /** @@ -760,8 +771,8 @@ public static function ucfirst($string) public static function uuid() { return static::$uuidFactory - ? call_user_func(static::$uuidFactory) - : Uuid::uuid4(); + ? call_user_func(static::$uuidFactory) + : Uuid::uuid4(); } /** @@ -777,14 +788,18 @@ public static function orderedUuid() $factory = new UuidFactory(); - $factory->setRandomGenerator(new CombGenerator( - $factory->getRandomGenerator(), - $factory->getNumberConverter() - )); + $factory->setRandomGenerator( + new CombGenerator( + $factory->getRandomGenerator(), + $factory->getNumberConverter() + ) + ); - $factory->setCodec(new TimestampFirstCombCodec( - $factory->getUuidBuilder() - )); + $factory->setCodec( + new TimestampFirstCombCodec( + $factory->getUuidBuilder() + ) + ); return $factory->uuid4(); } @@ -792,7 +807,7 @@ public static function orderedUuid() /** * Set the callable that will be used to generate UUIDs. * - * @param callable|null $factory + * @param callable|null $factory * @return void */ public static function createUuidsUsing(callable $factory = null) diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index d6a26b48607e..56b8fc1b853d 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -376,6 +376,7 @@ public function testRemove() $this->assertSame("Fbr", Str::remove(["o", "a"], 'Foobar')); $this->assertSame("Fooar", Str::remove(["f", "b"], 'Foobar')); $this->assertSame("ooar", Str::remove(["f", "b"], 'Foobar', false)); + $this->assertSame("Foobar", Str::remove(["f", "|"], 'Foo|bar')); } public function testSnake() diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index 89fe1fb9c000..8cce8dc14498 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -464,6 +464,7 @@ public function testRemove() $this->assertSame("Fbr", (string) $this->stringable('Foobar')->remove(["o", "a"])); $this->assertSame("Fooar", (string) $this->stringable('Foobar')->remove(["f", "b"])); $this->assertSame("ooar", (string) $this->stringable('Foobar')->remove(["f", "b"], false)); + $this->assertSame("Foobar", (string) $this->stringable('Foo|bar')->remove(["f", "|"])); } public function testSnake() From 61fb05ded8c2d001dbfaf7426b60d1b916635330 Mon Sep 17 00:00:00 2001 From: luke Date: Wed, 17 Mar 2021 21:10:15 +0000 Subject: [PATCH 4/5] Formatting fix --- src/Illuminate/Support/Str.php | 510 ++++++++++++++++----------------- 1 file changed, 253 insertions(+), 257 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 17e5e29e501c..19363d65a935 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -45,7 +45,7 @@ class Str /** * Get a new stringable object from the given string. * - * @param string $string + * @param string $string * @return \Illuminate\Support\Stringable */ public static function of($string) @@ -53,11 +53,23 @@ public static function of($string) return new Stringable($string); } + /** + * Return the remainder of a string after the first occurrence of a given value. + * + * @param string $subject + * @param string $search + * @return string + */ + public static function after($subject, $search) + { + return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0]; + } + /** * Return the remainder of a string after the last occurrence of a given value. * - * @param string $subject - * @param string $search + * @param string $subject + * @param string $search * @return string */ public static function afterLast($subject, $search) @@ -66,7 +78,7 @@ public static function afterLast($subject, $search) return $subject; } - $position = strrpos($subject, (string)$search); + $position = strrpos($subject, (string) $search); if ($position === false) { return $subject; @@ -76,45 +88,40 @@ public static function afterLast($subject, $search) } /** - * Get the portion of a string before the first occurrence of a given value. + * Transliterate a UTF-8 value to ASCII. * - * @param string $subject - * @param string $search + * @param string $value + * @param string $language * @return string */ - public static function before($subject, $search) + public static function ascii($value, $language = 'en') { - if ($search === '') { - return $subject; - } - - $result = strstr($subject, (string)$search, true); - - return $result === false ? $subject : $result; + return ASCII::to_ascii((string) $value, $language); } /** - * Get the portion of a string between two given values. + * Get the portion of a string before the first occurrence of a given value. * - * @param string $subject - * @param string $from - * @param string $to + * @param string $subject + * @param string $search * @return string */ - public static function between($subject, $from, $to) + public static function before($subject, $search) { - if ($from === '' || $to === '') { + if ($search === '') { return $subject; } - return static::beforeLast(static::after($subject, $from), $to); + $result = strstr($subject, (string) $search, true); + + return $result === false ? $subject : $result; } /** * Get the portion of a string before the last occurrence of a given value. * - * @param string $subject - * @param string $search + * @param string $subject + * @param string $search * @return string */ public static function beforeLast($subject, $search) @@ -133,34 +140,26 @@ public static function beforeLast($subject, $search) } /** - * Returns the portion of the string specified by the start and length parameters. + * Get the portion of a string between two given values. * - * @param string $string - * @param int $start - * @param int|null $length + * @param string $subject + * @param string $from + * @param string $to * @return string */ - public static function substr($string, $start, $length = null) + public static function between($subject, $from, $to) { - return mb_substr($string, $start, $length, 'UTF-8'); - } + if ($from === '' || $to === '') { + return $subject; + } - /** - * Return the remainder of a string after the first occurrence of a given value. - * - * @param string $subject - * @param string $search - * @return string - */ - public static function after($subject, $search) - { - return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0]; + return static::beforeLast(static::after($subject, $from), $to); } /** * Convert a value to camel case. * - * @param string $value + * @param string $value * @return string */ public static function camel($value) @@ -173,35 +172,34 @@ public static function camel($value) } /** - * Convert a value to studly caps case. + * Determine if a given string contains a given substring. * - * @param string $value - * @return string + * @param string $haystack + * @param string|string[] $needles + * @return bool */ - public static function studly($value) + public static function contains($haystack, $needles) { - $key = $value; - - if (isset(static::$studlyCache[$key])) { - return static::$studlyCache[$key]; + foreach ((array) $needles as $needle) { + if ($needle !== '' && mb_strpos($haystack, $needle) !== false) { + return true; + } } - $value = ucwords(str_replace(['-', '_'], ' ', $value)); - - return static::$studlyCache[$key] = str_replace(' ', '', $value); + return false; } /** * Determine if a given string contains all array values. * - * @param string $haystack - * @param string[] $needles + * @param string $haystack + * @param string[] $needles * @return bool */ public static function containsAll($haystack, array $needles) { foreach ($needles as $needle) { - if (!static::contains($haystack, $needle)) { + if (! static::contains($haystack, $needle)) { return false; } } @@ -209,35 +207,17 @@ public static function containsAll($haystack, array $needles) return true; } - /** - * Determine if a given string contains a given substring. - * - * @param string $haystack - * @param string|string[] $needles - * @return bool - */ - public static function contains($haystack, $needles) - { - foreach ((array)$needles as $needle) { - if ($needle !== '' && mb_strpos($haystack, $needle) !== false) { - return true; - } - } - - return false; - } - /** * Determine if a given string ends with a given substring. * - * @param string $haystack - * @param string|string[] $needles + * @param string $haystack + * @param string|string[] $needles * @return bool */ public static function endsWith($haystack, $needles) { - foreach ((array)$needles as $needle) { - if ($needle !== '' && substr($haystack, -strlen($needle)) === (string)$needle) { + foreach ((array) $needles as $needle) { + if ($needle !== '' && substr($haystack, -strlen($needle)) === (string) $needle) { return true; } } @@ -248,22 +228,22 @@ public static function endsWith($haystack, $needles) /** * Cap a string with a single instance of a given value. * - * @param string $value - * @param string $cap + * @param string $value + * @param string $cap * @return string */ public static function finish($value, $cap) { $quoted = preg_quote($cap, '/'); - return preg_replace('/(?:' . $quoted . ')+$/u', '', $value) . $cap; + return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap; } /** * Determine if a given string matches a given pattern. * - * @param string|array $pattern - * @param string $value + * @param string|array $pattern + * @param string $value * @return bool */ public static function is($pattern, $value) @@ -289,7 +269,7 @@ public static function is($pattern, $value) // pattern such as "library/*", making any string check convenient. $pattern = str_replace('\*', '.*', $pattern); - if (preg_match('#^' . $pattern . '\z#u', $value) === 1) { + if (preg_match('#^'.$pattern.'\z#u', $value) === 1) { return true; } } @@ -300,23 +280,23 @@ public static function is($pattern, $value) /** * Determine if a given string is 7 bit ASCII. * - * @param string $value + * @param string $value * @return bool */ public static function isAscii($value) { - return ASCII::is_ascii((string)$value); + return ASCII::is_ascii((string) $value); } /** * Determine if a given string is a valid UUID. * - * @param string $value + * @param string $value * @return bool */ public static function isUuid($value) { - if (!is_string($value)) { + if (! is_string($value)) { return false; } @@ -326,7 +306,7 @@ public static function isUuid($value) /** * Convert a string to kebab case. * - * @param string $value + * @param string $value * @return string */ public static function kebab($value) @@ -335,46 +315,27 @@ public static function kebab($value) } /** - * Convert a string to snake case. + * Return the length of the given string. * - * @param string $value - * @param string $delimiter - * @return string + * @param string $value + * @param string|null $encoding + * @return int */ - public static function snake($value, $delimiter = '_') + public static function length($value, $encoding = null) { - $key = $value; - - if (isset(static::$snakeCache[$key][$delimiter])) { - return static::$snakeCache[$key][$delimiter]; - } - - if (!ctype_lower($value)) { - $value = preg_replace('/\s+/u', '', ucwords($value)); - - $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value)); + if ($encoding) { + return mb_strlen($value, $encoding); } - return static::$snakeCache[$key][$delimiter] = $value; - } - - /** - * Convert the given string to lower-case. - * - * @param string $value - * @return string - */ - public static function lower($value) - { - return mb_strtolower($value, 'UTF-8'); + return mb_strlen($value); } /** * Limit the number of characters in a string. * - * @param string $value - * @param int $limit - * @param string $end + * @param string $value + * @param int $limit + * @param string $end * @return string */ public static function limit($value, $limit = 100, $end = '...') @@ -383,49 +344,44 @@ public static function limit($value, $limit = 100, $end = '...') return $value; } - return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end; + return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end; } /** - * Limit the number of words in a string. + * Convert the given string to lower-case. * - * @param string $value - * @param int $words - * @param string $end + * @param string $value * @return string */ - public static function words($value, $words = 100, $end = '...') + public static function lower($value) { - preg_match('/^\s*+(?:\S++\s*+){1,' . $words . '}/u', $value, $matches); - - if (!isset($matches[0]) || static::length($value) === static::length($matches[0])) { - return $value; - } - - return rtrim($matches[0]) . $end; + return mb_strtolower($value, 'UTF-8'); } /** - * Return the length of the given string. + * Limit the number of words in a string. * - * @param string $value - * @param string|null $encoding - * @return int + * @param string $value + * @param int $words + * @param string $end + * @return string */ - public static function length($value, $encoding = null) + public static function words($value, $words = 100, $end = '...') { - if ($encoding) { - return mb_strlen($value, $encoding); + preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches); + + if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) { + return $value; } - return mb_strlen($value); + return rtrim($matches[0]).$end; } /** * Converts GitHub flavored Markdown into HTML. * - * @param string $string - * @param array $options + * @param string $string + * @param array $options * @return string */ public static function markdown($string, array $options = []) @@ -438,9 +394,9 @@ public static function markdown($string, array $options = []) /** * Pad both sides of a string with another. * - * @param string $value - * @param int $length - * @param string $pad + * @param string $value + * @param int $length + * @param string $pad * @return string */ public static function padBoth($value, $length, $pad = ' ') @@ -451,9 +407,9 @@ public static function padBoth($value, $length, $pad = ' ') /** * Pad the left side of a string with another. * - * @param string $value - * @param int $length - * @param string $pad + * @param string $value + * @param int $length + * @param string $pad * @return string */ public static function padLeft($value, $length, $pad = ' ') @@ -464,9 +420,9 @@ public static function padLeft($value, $length, $pad = ' ') /** * Pad the right side of a string with another. * - * @param string $value - * @param int $length - * @param string $pad + * @param string $value + * @param int $length + * @param string $pad * @return string */ public static function padRight($value, $length, $pad = ' ') @@ -477,8 +433,8 @@ public static function padRight($value, $length, $pad = ' ') /** * Parse a Class[@]method style callback into class and method. * - * @param string $callback - * @param string|null $default + * @param string $callback + * @param string|null $default * @return array */ public static function parseCallback($callback, $default = null) @@ -487,37 +443,37 @@ public static function parseCallback($callback, $default = null) } /** - * Pluralize the last word of an English, studly caps case string. + * Get the plural form of an English word. * - * @param string $value - * @param int $count + * @param string $value + * @param int $count * @return string */ - public static function pluralStudly($value, $count = 2) + public static function plural($value, $count = 2) { - $parts = preg_split('/(.)(?=[A-Z])/u', $value, -1, PREG_SPLIT_DELIM_CAPTURE); - - $lastWord = array_pop($parts); - - return implode('', $parts) . self::plural($lastWord, $count); + return Pluralizer::plural($value, $count); } /** - * Get the plural form of an English word. + * Pluralize the last word of an English, studly caps case string. * - * @param string $value - * @param int $count + * @param string $value + * @param int $count * @return string */ - public static function plural($value, $count = 2) + public static function pluralStudly($value, $count = 2) { - return Pluralizer::plural($value, $count); + $parts = preg_split('/(.)(?=[A-Z])/u', $value, -1, PREG_SPLIT_DELIM_CAPTURE); + + $lastWord = array_pop($parts); + + return implode('', $parts).self::plural($lastWord, $count); } /** * Generate a more truly "random" alpha-numeric string. * - * @param int $length + * @param int $length * @return string */ public static function random($length = 16) @@ -535,38 +491,12 @@ public static function random($length = 16) return $string; } - /** - * Remove any occurrence of the given string in the subject. - * - * @param string|array $search - * @param string $subject - * @param bool $caseSensitive - * @return string - */ - public static function remove($search, $subject, $caseSensitive = true) - { - $regexSafeSearches = array_map( - function ($search) { - return preg_quote($search); - }, - is_array($search) ? $search : [$search] - ); - - $regex = "/" . implode("|", $regexSafeSearches) . "/"; - - if (!$caseSensitive) { - $regex .= "i"; - } - - return preg_replace($regex, "", $subject); - } - /** * Replace a given value in the string sequentially with an array. * - * @param string $search - * @param array $replace - * @param string $subject + * @param string $search + * @param array $replace + * @param string $subject * @return string */ public static function replaceArray($search, array $replace, $subject) @@ -576,7 +506,7 @@ public static function replaceArray($search, array $replace, $subject) $result = array_shift($segments); foreach ($segments as $segment) { - $result .= (array_shift($replace) ?? $search) . $segment; + $result .= (array_shift($replace) ?? $search).$segment; } return $result; @@ -585,9 +515,9 @@ public static function replaceArray($search, array $replace, $subject) /** * Replace the first occurrence of a given value in the string. * - * @param string $search - * @param string $replace - * @param string $subject + * @param string $search + * @param string $replace + * @param string $subject * @return string */ public static function replaceFirst($search, $replace, $subject) @@ -608,9 +538,9 @@ public static function replaceFirst($search, $replace, $subject) /** * Replace the last occurrence of a given value in the string. * - * @param string $search - * @param string $replace - * @param string $subject + * @param string $search + * @param string $replace + * @param string $subject * @return string */ public static function replaceLast($search, $replace, $subject) @@ -628,24 +558,61 @@ public static function replaceLast($search, $replace, $subject) return $subject; } + /** + * Remove any occurrence of the given string in the subject. + * + * @param string|array $search + * @param string $subject + * @param bool $caseSensitive + * @return string + */ + public static function remove($search, $subject, $caseSensitive = true) + { + $regexSafeSearches = array_map( + function ($search) { + return preg_quote($search); + }, + is_array($search) ? $search : [$search] + ); + + $regex = "/" . implode("|", $regexSafeSearches) . "/"; + + if (!$caseSensitive) { + $regex .= "i"; + } + + return preg_replace($regex, "", $subject); + } + /** * Begin a string with a single instance of a given value. * - * @param string $value - * @param string $prefix + * @param string $value + * @param string $prefix * @return string */ public static function start($value, $prefix) { $quoted = preg_quote($prefix, '/'); - return $prefix . preg_replace('/^(?:' . $quoted . ')+/u', '', $value); + return $prefix.preg_replace('/^(?:'.$quoted.')+/u', '', $value); + } + + /** + * Convert the given string to upper-case. + * + * @param string $value + * @return string + */ + public static function upper($value) + { + return mb_strtoupper($value, 'UTF-8'); } /** * Convert the given string to title case. * - * @param string $value + * @param string $value * @return string */ public static function title($value) @@ -656,7 +623,7 @@ public static function title($value) /** * Get the singular form of an English word. * - * @param string $value + * @param string $value * @return string */ public static function singular($value) @@ -667,9 +634,9 @@ public static function singular($value) /** * Generate a URL friendly "slug" from a given string. * - * @param string $title - * @param string $separator - * @param string|null $language + * @param string $title + * @param string $separator + * @param string|null $language * @return string */ public static function slug($title, $separator = '-', $language = 'en') @@ -679,43 +646,55 @@ public static function slug($title, $separator = '-', $language = 'en') // Convert all dashes/underscores into separator $flip = $separator === '-' ? '_' : '-'; - $title = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $title); + $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); // Replace @ with the word 'at' - $title = str_replace('@', $separator . 'at' . $separator, $title); + $title = str_replace('@', $separator.'at'.$separator, $title); // Remove all characters that are not the separator, letters, numbers, or whitespace. - $title = preg_replace('![^' . preg_quote($separator) . '\pL\pN\s]+!u', '', static::lower($title)); + $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', static::lower($title)); // Replace all separator characters and whitespace by a single separator - $title = preg_replace('![' . preg_quote($separator) . '\s]+!u', $separator, $title); + $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); return trim($title, $separator); } /** - * Transliterate a UTF-8 value to ASCII. + * Convert a string to snake case. * - * @param string $value - * @param string $language + * @param string $value + * @param string $delimiter * @return string */ - public static function ascii($value, $language = 'en') + public static function snake($value, $delimiter = '_') { - return ASCII::to_ascii((string)$value, $language); + $key = $value; + + if (isset(static::$snakeCache[$key][$delimiter])) { + return static::$snakeCache[$key][$delimiter]; + } + + if (! ctype_lower($value)) { + $value = preg_replace('/\s+/u', '', ucwords($value)); + + $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value)); + } + + return static::$snakeCache[$key][$delimiter] = $value; } /** * Determine if a given string starts with a given substring. * - * @param string $haystack - * @param string|string[] $needles + * @param string $haystack + * @param string|string[] $needles * @return bool */ public static function startsWith($haystack, $needles) { - foreach ((array)$needles as $needle) { - if ((string)$needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0) { + foreach ((array) $needles as $needle) { + if ((string) $needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0) { return true; } } @@ -723,18 +702,50 @@ public static function startsWith($haystack, $needles) return false; } + /** + * Convert a value to studly caps case. + * + * @param string $value + * @return string + */ + public static function studly($value) + { + $key = $value; + + if (isset(static::$studlyCache[$key])) { + return static::$studlyCache[$key]; + } + + $value = ucwords(str_replace(['-', '_'], ' ', $value)); + + return static::$studlyCache[$key] = str_replace(' ', '', $value); + } + + /** + * Returns the portion of the string specified by the start and length parameters. + * + * @param string $string + * @param int $start + * @param int|null $length + * @return string + */ + public static function substr($string, $start, $length = null) + { + return mb_substr($string, $start, $length, 'UTF-8'); + } + /** * Returns the number of substring occurrences. * - * @param string $haystack - * @param string $needle - * @param int $offset - * @param int|null $length + * @param string $haystack + * @param string $needle + * @param int $offset + * @param int|null $length * @return int */ public static function substrCount($haystack, $needle, $offset = 0, $length = null) { - if (!is_null($length)) { + if (! is_null($length)) { return substr_count($haystack, $needle, $offset, $length); } else { return substr_count($haystack, $needle, $offset); @@ -744,23 +755,12 @@ public static function substrCount($haystack, $needle, $offset = 0, $length = nu /** * Make a string's first character uppercase. * - * @param string $string + * @param string $string * @return string */ public static function ucfirst($string) { - return static::upper(static::substr($string, 0, 1)) . static::substr($string, 1); - } - - /** - * Convert the given string to upper-case. - * - * @param string $value - * @return string - */ - public static function upper($value) - { - return mb_strtoupper($value, 'UTF-8'); + return static::upper(static::substr($string, 0, 1)).static::substr($string, 1); } /** @@ -771,8 +771,8 @@ public static function upper($value) public static function uuid() { return static::$uuidFactory - ? call_user_func(static::$uuidFactory) - : Uuid::uuid4(); + ? call_user_func(static::$uuidFactory) + : Uuid::uuid4(); } /** @@ -788,18 +788,14 @@ public static function orderedUuid() $factory = new UuidFactory(); - $factory->setRandomGenerator( - new CombGenerator( - $factory->getRandomGenerator(), - $factory->getNumberConverter() - ) - ); + $factory->setRandomGenerator(new CombGenerator( + $factory->getRandomGenerator(), + $factory->getNumberConverter() + )); - $factory->setCodec( - new TimestampFirstCombCodec( - $factory->getUuidBuilder() - ) - ); + $factory->setCodec(new TimestampFirstCombCodec( + $factory->getUuidBuilder() + )); return $factory->uuid4(); } @@ -807,7 +803,7 @@ public static function orderedUuid() /** * Set the callable that will be used to generate UUIDs. * - * @param callable|null $factory + * @param callable|null $factory * @return void */ public static function createUuidsUsing(callable $factory = null) From 7b0259faa46409513b75a8a0b512b3aacfcad944 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 18 Mar 2021 08:16:29 -0500 Subject: [PATCH 5/5] Update Str.php --- src/Illuminate/Support/Str.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 19363d65a935..f904ae597ed5 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -568,16 +568,13 @@ public static function replaceLast($search, $replace, $subject) */ public static function remove($search, $subject, $caseSensitive = true) { - $regexSafeSearches = array_map( - function ($search) { - return preg_quote($search); - }, - is_array($search) ? $search : [$search] - ); + $regexSafeSearches = array_map(function ($search) { + return preg_quote($search); + }, is_array($search) ? $search : [$search]); - $regex = "/" . implode("|", $regexSafeSearches) . "/"; + $regex = "/".implode("|", $regexSafeSearches)."/"; - if (!$caseSensitive) { + if (! $caseSensitive) { $regex .= "i"; }