Skip to content

Commit e8a8700

Browse files
committed
style: fix Pint formatting in Str and SupportStrTest
1 parent 5271b54 commit e8a8700

File tree

2 files changed

+56
-61
lines changed

2 files changed

+56
-61
lines changed

src/Illuminate/Support/Str.php

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,12 @@ public static function convertCase(string $string, int $mode = MB_CASE_FOLD, ?st
376376
public static function deduplicate(string $string, array|string $characters = ' ')
377377
{
378378
if (is_string($characters)) {
379-
return preg_replace('/' . preg_quote($characters, '/') . '+/u', $characters, $string);
379+
return preg_replace('/'.preg_quote($characters, '/').'+/u', $characters, $string);
380380
}
381381

382382
return array_reduce(
383383
$characters,
384-
fn($carry, $character) => preg_replace('/' . preg_quote($character, '/') . '+/u', $character, $carry),
384+
fn ($carry, $character) => preg_replace('/'.preg_quote($character, '/').'+/u', $character, $carry),
385385
$string
386386
);
387387
}
@@ -437,7 +437,7 @@ public static function excerpt($text, $phrase = '', $options = [])
437437
$radius = $options['radius'] ?? 100;
438438
$omission = $options['omission'] ?? '...';
439439

440-
preg_match('/^(.*?)(' . preg_quote((string) $phrase, '/') . ')(.*)$/iu', (string) $text, $matches);
440+
preg_match('/^(.*?)('.preg_quote((string) $phrase, '/').')(.*)$/iu', (string) $text, $matches);
441441

442442
if (empty($matches)) {
443443
return null;
@@ -446,15 +446,15 @@ public static function excerpt($text, $phrase = '', $options = [])
446446
$start = ltrim($matches[1]);
447447

448448
$start = Str::of(mb_substr($start, max(mb_strlen($start, 'UTF-8') - $radius, 0), $radius, 'UTF-8'))->ltrim()->unless(
449-
fn($startWithRadius) => $startWithRadius->exactly($start),
450-
fn($startWithRadius) => $startWithRadius->prepend($omission),
449+
fn ($startWithRadius) => $startWithRadius->exactly($start),
450+
fn ($startWithRadius) => $startWithRadius->prepend($omission),
451451
);
452452

453453
$end = rtrim($matches[3]);
454454

455455
$end = Str::of(mb_substr($end, 0, $radius, 'UTF-8'))->rtrim()->unless(
456-
fn($endWithRadius) => $endWithRadius->exactly($end),
457-
fn($endWithRadius) => $endWithRadius->append($omission),
456+
fn ($endWithRadius) => $endWithRadius->exactly($end),
457+
fn ($endWithRadius) => $endWithRadius->append($omission),
458458
);
459459

460460
return $start->append($matches[2], $end)->toString();
@@ -471,7 +471,7 @@ public static function finish($value, $cap)
471471
{
472472
$quoted = preg_quote($cap, '/');
473473

474-
return preg_replace('/(?:' . $quoted . ')+$/u', '', $value) . $cap;
474+
return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap;
475475
}
476476

477477
/**
@@ -484,7 +484,7 @@ public static function finish($value, $cap)
484484
*/
485485
public static function wrap($value, $before, $after = null)
486486
{
487-
return $before . $value . ($after ?? $before);
487+
return $before.$value.($after ?? $before);
488488
}
489489

490490
/**
@@ -545,7 +545,7 @@ public static function is($pattern, $value, $ignoreCase = false)
545545
// pattern such as "library/*", making any string check convenient.
546546
$pattern = str_replace('\*', '.*', $pattern);
547547

548-
if (preg_match('#^' . $pattern . '\z#' . ($ignoreCase ? 'isu' : 'su'), $value) === 1) {
548+
if (preg_match('#^'.$pattern.'\z#'.($ignoreCase ? 'isu' : 'su'), $value) === 1) {
549549
return true;
550550
}
551551
}
@@ -718,18 +718,18 @@ public static function limit($value, $limit = 100, $end = '...', $preserveWords
718718
}
719719

720720
if (! $preserveWords) {
721-
return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end;
721+
return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end;
722722
}
723723

724724
$value = trim(preg_replace('/[\n\r]+/', ' ', strip_tags($value)));
725725

726726
$trimmed = rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8'));
727727

728728
if (mb_substr($value, $limit, 1, 'UTF-8') === ' ') {
729-
return $trimmed . $end;
729+
return $trimmed.$end;
730730
}
731731

732-
return preg_replace("/(.*)\s.*/", '$1', $trimmed) . $end;
732+
return preg_replace("/(.*)\s.*/", '$1', $trimmed).$end;
733733
}
734734

735735
/**
@@ -753,13 +753,13 @@ public static function lower($value)
753753
*/
754754
public static function words($value, $words = 100, $end = '...')
755755
{
756-
preg_match('/^\s*+(?:\S++\s*+){1,' . $words . '}/u', $value, $matches);
756+
preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches);
757757

758758
if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) {
759759
return $value;
760760
}
761761

762-
return rtrim($matches[0]) . $end;
762+
return rtrim($matches[0]).$end;
763763
}
764764

765765
/**
@@ -840,7 +840,7 @@ public static function mask($string, $character, $index, $length = null, $encodi
840840
$segmentLen = mb_strlen($segment, $encoding);
841841
$end = mb_substr($string, $startIndex + $segmentLen);
842842

843-
return $start . str_repeat(mb_substr($character, 0, 1, $encoding), $segmentLen) . $end;
843+
return $start.str_repeat(mb_substr($character, 0, 1, $encoding), $segmentLen).$end;
844844
}
845845

846846
/**
@@ -988,7 +988,7 @@ public static function parseCallback($callback, $default = null)
988988
*/
989989
public static function plural($value, $count = 2, $prependCount = false)
990990
{
991-
return ($prependCount ? Number::format($count) . ' ' : '') . Pluralizer::plural($value, $count);
991+
return ($prependCount ? Number::format($count).' ' : '').Pluralizer::plural($value, $count);
992992
}
993993

994994
/**
@@ -1004,7 +1004,7 @@ public static function pluralStudly($value, $count = 2)
10041004

10051005
$lastWord = array_pop($parts);
10061006

1007-
return implode('', $parts) . self::plural($lastWord, $count);
1007+
return implode('', $parts).self::plural($lastWord, $count);
10081008
}
10091009

10101010
/**
@@ -1131,13 +1131,13 @@ public static function password($length = 32, $letters = true, $numbers = true,
11311131
'spaces' => $spaces === true ? [' '] : null,
11321132
]))
11331133
->filter()
1134-
->each(fn($c) => $password->push($c[random_int(0, count($c) - 1)]))
1134+
->each(fn ($c) => $password->push($c[random_int(0, count($c) - 1)]))
11351135
->flatten();
11361136

11371137
$length = $length - $password->count();
11381138

11391139
return $password->merge($options->pipe(
1140-
fn($c) => Collection::times($length, fn() => $c[random_int(0, $c->count() - 1)])
1140+
fn ($c) => Collection::times($length, fn () => $c[random_int(0, $c->count() - 1)])
11411141
))->shuffle()->implode('');
11421142
}
11431143

@@ -1266,7 +1266,7 @@ public static function replaceArray($search, $replace, $subject)
12661266
$result = array_shift($segments);
12671267

12681268
foreach ($segments as $segment) {
1269-
$result .= self::toStringOr(array_shift($replace) ?? $search, $search) . $segment;
1269+
$result .= self::toStringOr(array_shift($replace) ?? $search, $search).$segment;
12701270
}
12711271

12721272
return $result;
@@ -1471,7 +1471,7 @@ public static function start($value, $prefix)
14711471
{
14721472
$quoted = preg_quote($prefix, '/');
14731473

1474-
return $prefix . preg_replace('/^(?:' . $quoted . ')+/u', '', $value);
1474+
return $prefix.preg_replace('/^(?:'.$quoted.')+/u', '', $value);
14751475
}
14761476

14771477
/**
@@ -1581,7 +1581,7 @@ public static function apa($value)
15811581
$hyphenatedWords = array_map(function ($part) use ($minorWords) {
15821582
return (in_array($part, $minorWords) && mb_strlen($part) <= 3)
15831583
? $part
1584-
: mb_strtoupper(mb_substr($part, 0, 1)) . mb_substr($part, 1);
1584+
: mb_strtoupper(mb_substr($part, 0, 1)).mb_substr($part, 1);
15851585
}, $hyphenatedWords);
15861586

15871587
$words[$i] = implode('-', $hyphenatedWords);
@@ -1593,7 +1593,7 @@ public static function apa($value)
15931593
) {
15941594
$words[$i] = $lowercaseWord;
15951595
} else {
1596-
$words[$i] = mb_strtoupper(mb_substr($lowercaseWord, 0, 1)) . mb_substr($lowercaseWord, 1);
1596+
$words[$i] = mb_strtoupper(mb_substr($lowercaseWord, 0, 1)).mb_substr($lowercaseWord, 1);
15971597
}
15981598
}
15991599
}
@@ -1628,20 +1628,20 @@ public static function slug($title, $separator = '-', $language = 'en', $diction
16281628
// Convert all dashes/underscores into separator
16291629
$flip = $separator === '-' ? '_' : '-';
16301630

1631-
$title = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $title);
1631+
$title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);
16321632

16331633
// Replace dictionary words
16341634
foreach ($dictionary as $key => $value) {
1635-
$dictionary[$key] = $separator . $value . $separator;
1635+
$dictionary[$key] = $separator.$value.$separator;
16361636
}
16371637

16381638
$title = str_replace(array_keys($dictionary), array_values($dictionary), $title);
16391639

16401640
// Remove all characters that are not the separator, letters, numbers, or whitespace
1641-
$title = preg_replace('![^' . preg_quote($separator) . '\pL\pN\s]+!u', '', static::lower($title));
1641+
$title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', static::lower($title));
16421642

16431643
// Replace all separator characters and whitespace by a single separator
1644-
$title = preg_replace('![' . preg_quote($separator) . '\s]+!u', $separator, $title);
1644+
$title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title);
16451645

16461646
return trim($title, $separator);
16471647
}
@@ -1664,7 +1664,7 @@ public static function snake($value, $delimiter = '_')
16641664
if (! ctype_lower($value)) {
16651665
$value = preg_replace('/\s+/u', '', ucwords($value));
16661666

1667-
$value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value));
1667+
$value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value));
16681668
}
16691669

16701670
return static::$snakeCache[$key][$delimiter] = $value;
@@ -1682,7 +1682,7 @@ public static function trim($value, $charlist = null)
16821682
if ($charlist === null) {
16831683
$trimDefaultCharacters = " \n\r\t\v\0";
16841684

1685-
return preg_replace('~^[\s' . self::INVISIBLE_CHARACTERS . $trimDefaultCharacters . ']+|[\s' . self::INVISIBLE_CHARACTERS . $trimDefaultCharacters . ']+$~u', '', $value) ?? trim($value);
1685+
return preg_replace('~^[\s'.self::INVISIBLE_CHARACTERS.$trimDefaultCharacters.']+|[\s'.self::INVISIBLE_CHARACTERS.$trimDefaultCharacters.']+$~u', '', $value) ?? trim($value);
16861686
}
16871687

16881688
return trim($value, $charlist);
@@ -1700,7 +1700,7 @@ public static function ltrim($value, $charlist = null)
17001700
if ($charlist === null) {
17011701
$ltrimDefaultCharacters = " \n\r\t\v\0";
17021702

1703-
return preg_replace('~^[\s' . self::INVISIBLE_CHARACTERS . $ltrimDefaultCharacters . ']+~u', '', $value) ?? ltrim($value);
1703+
return preg_replace('~^[\s'.self::INVISIBLE_CHARACTERS.$ltrimDefaultCharacters.']+~u', '', $value) ?? ltrim($value);
17041704
}
17051705

17061706
return ltrim($value, $charlist);
@@ -1718,7 +1718,7 @@ public static function rtrim($value, $charlist = null)
17181718
if ($charlist === null) {
17191719
$rtrimDefaultCharacters = " \n\r\t\v\0";
17201720

1721-
return preg_replace('~[\s' . self::INVISIBLE_CHARACTERS . $rtrimDefaultCharacters . ']+$~u', '', $value) ?? rtrim($value);
1721+
return preg_replace('~[\s'.self::INVISIBLE_CHARACTERS.$rtrimDefaultCharacters.']+$~u', '', $value) ?? rtrim($value);
17221722
}
17231723

17241724
return rtrim($value, $charlist);
@@ -1789,7 +1789,7 @@ public static function studly($value)
17891789

17901790
$words = mb_split('\s+', static::replace(['-', '_'], ' ', $value));
17911791

1792-
$studlyWords = array_map(fn($word) => static::ucfirst($word), $words);
1792+
$studlyWords = array_map(fn ($word) => static::ucfirst($word), $words);
17931793

17941794
return static::$studlyCache[$key] = implode($studlyWords);
17951795
}
@@ -1914,7 +1914,7 @@ public static function fromBase64($string, $strict = false)
19141914
*/
19151915
public static function lcfirst($string)
19161916
{
1917-
return static::lower(static::substr($string, 0, 1)) . static::substr($string, 1);
1917+
return static::lower(static::substr($string, 0, 1)).static::substr($string, 1);
19181918
}
19191919

19201920
/**
@@ -1925,7 +1925,7 @@ public static function lcfirst($string)
19251925
*/
19261926
public static function ucfirst($string)
19271927
{
1928-
return static::upper(static::substr($string, 0, 1)) . static::substr($string, 1);
1928+
return static::upper(static::substr($string, 0, 1)).static::substr($string, 1);
19291929
}
19301930

19311931
/**
@@ -2070,7 +2070,7 @@ public static function freezeUuids(?Closure $callback = null)
20702070
{
20712071
$uuid = Str::uuid();
20722072

2073-
Str::createUuidsUsing(fn() => $uuid);
2073+
Str::createUuidsUsing(fn () => $uuid);
20742074

20752075
if ($callback !== null) {
20762076
try {
@@ -2177,7 +2177,7 @@ public static function freezeUlids(?Closure $callback = null)
21772177
{
21782178
$ulid = Str::ulid();
21792179

2180-
Str::createUlidsUsing(fn() => $ulid);
2180+
Str::createUlidsUsing(fn () => $ulid);
21812181

21822182
if ($callback !== null) {
21832183
try {
@@ -2210,10 +2210,10 @@ public static function flushCache()
22102210
* and optionally keeps only tokens that exactly match the given list.
22112211
*
22122212
* @param string $subject
2213-
* @param array<string> $remove Characters or substrings to strip from each token
2214-
* @param array<string> $ignore Tokens containing these values will be discarded
2215-
* @param array<string,string> $replace Key/value pairs to replace within each token
2216-
* @param array<string> $match Tokens must exactly match one of these values to be kept
2213+
* @param array<string> $remove Characters or substrings to strip from each token
2214+
* @param array<string> $ignore Tokens containing these values will be discarded
2215+
* @param array<string,string> $replace Key/value pairs to replace within each token
2216+
* @param array<string> $match Tokens must exactly match one of these values to be kept
22172217
* @return \Illuminate\Support\Collection<string>
22182218
*/
22192219
public static function tokens(
@@ -2226,18 +2226,14 @@ public static function tokens(
22262226
return collect(
22272227
preg_split('/[\s,;]+/', $subject, -1, PREG_SPLIT_NO_EMPTY) ?: []
22282228
)
2229-
->when(! empty($remove), fn ($c) =>
2230-
$c->map(fn ($t) => static::remove($remove, $t))
2231-
)
2232-
->when(! empty($replace), fn ($c) =>
2233-
$c->map(fn ($t) => strtr($t, $replace))
2234-
)
2235-
->when(! empty($ignore), fn ($c) =>
2236-
$c->reject(fn ($t) => static::contains($t, $ignore))
2237-
)
2238-
->when(! empty($match), fn ($c) =>
2239-
$c->filter(fn ($t) => static::is($match, $t))
2240-
)
2241-
->values();
2229+
->when(! empty($remove), fn ($c) => $c->map(fn ($t) => static::remove($remove, $t))
2230+
)
2231+
->when(! empty($replace), fn ($c) => $c->map(fn ($t) => strtr($t, $replace))
2232+
)
2233+
->when(! empty($ignore), fn ($c) => $c->reject(fn ($t) => static::contains($t, $ignore))
2234+
)
2235+
->when(! empty($match), fn ($c) => $c->filter(fn ($t) => static::is($match, $t))
2236+
)
2237+
->values();
22422238
}
22432239
}

tests/Support/SupportStrTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,42 +1893,42 @@ public function count(): int
18931893

18941894
public function testTokensCanRemoveCharacters()
18951895
{
1896-
$text = "foo=1, bar=2";
1896+
$text = 'foo=1, bar=2';
18971897
$result = Str::tokens($text, remove: ['=', ',']);
18981898
$this->assertEquals(['foo1', 'bar2'], $result->all());
18991899
}
19001900

19011901
public function testTokensCanReplaceCharacters()
19021902
{
1903-
$text = "hello_user [email protected]";
1903+
$text = 'hello_user [email protected]';
19041904
$result = Str::tokens($text, replace: ['_' => '-', '@' => '[at]']);
19051905
$this->assertEquals(['hello-user', 'test[at]example.com'], $result->all());
19061906
}
19071907

19081908
public function testTokensCanIgnoreTokens()
19091909
{
1910-
$text = "ignoreme keepme";
1910+
$text = 'ignoreme keepme';
19111911
$result = Str::tokens($text, ignore: ['ignoreme']);
19121912
$this->assertEquals(['keepme'], $result->all());
19131913
}
19141914

19151915
public function testTokensCanMatchExactTokens()
19161916
{
1917-
$text = "red green blue";
1917+
$text = 'red green blue';
19181918
$result = Str::tokens($text, match: ['green']);
19191919
$this->assertEquals(['green'], $result->all());
19201920
}
19211921

19221922
public function testTokensCanMatchWithWildcard()
19231923
{
1924-
1924+
19251925
$result = Str::tokens($text, match: ['*example.com']);
19261926
$this->assertEquals(['[email protected]'], $result->all());
19271927
}
19281928

19291929
public function testTokensCanParseLogEntry()
19301930
{
1931-
$text = "2025-09-09 12:30:01, ERROR: User [email protected] failed login attempt from IP=192.168.1.10.";
1931+
$text = '2025-09-09 12:30:01, ERROR: User [email protected] failed login attempt from IP=192.168.1.10.';
19321932

19331933
$result = Str::tokens(
19341934
$text,
@@ -1944,7 +1944,6 @@ public function testTokensCanParseLogEntry()
19441944
);
19451945
}
19461946

1947-
19481947
}
19491948

19501949
class StringableObjectStub

0 commit comments

Comments
 (0)