Skip to content

Commit e3e4655

Browse files
committed
Merge branch 'cleanup'
2 parents 650a4cf + 857e906 commit e3e4655

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/Toolkit/Utility/Get.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,8 @@ private static function doCode(
746746
*
747747
* Recognised line endings are LF (`"\n"`), CRLF (`"\r\n"`) and CR (`"\r"`).
748748
*
749-
* @return string|null `null` if there are no recognised line breaks in
750-
* `$string`.
749+
* @return non-empty-string|null `null` if there are no recognised line
750+
* breaks in `$string`.
751751
*
752752
* @see Filesystem::getEol()
753753
* @see Str::setEol()

src/Toolkit/Utility/Str.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,23 @@ public static function coalesce(?string ...$strings): ?string
3939
}
4040

4141
/**
42-
* Convert ASCII alphabetic characters in a string to lowercase
42+
* Convert an ASCII string to lowercase
4343
*/
4444
public static function lower(string $string): string
4545
{
4646
return strtr($string, self::UPPER, self::LOWER);
4747
}
4848

4949
/**
50-
* Convert ASCII alphabetic characters in a string to uppercase
50+
* Convert an ASCII string to uppercase
5151
*/
5252
public static function upper(string $string): string
5353
{
5454
return strtr($string, self::LOWER, self::UPPER);
5555
}
5656

5757
/**
58-
* If the first character in a string is an ASCII alphabetic character, make
59-
* it uppercase
58+
* Make the first character in an ASCII string uppercase
6059
*/
6160
public static function upperFirst(string $string): string
6261
{
@@ -102,7 +101,7 @@ public static function matchCase(string $string, string $match): string
102101
}
103102

104103
/**
105-
* Check if a string starts with any of the given substrings
104+
* Check if a string starts with a given substring
106105
*
107106
* @param iterable<string>|string $needles
108107
*/
@@ -124,7 +123,7 @@ public static function startsWith(string $haystack, $needles, bool $ignoreCase =
124123
}
125124

126125
/**
127-
* Check if a string ends with any of the given substrings
126+
* Check if a string ends with a given substring
128127
*
129128
* @param iterable<string>|string $needles
130129
*/
@@ -369,7 +368,9 @@ public static function words(
369368
}
370369

371370
/**
372-
* Expand tabs to spaces
371+
* Expand tabs in a string to spaces
372+
*
373+
* @param int $column The starting column (1-based) of `$text`.
373374
*/
374375
public static function expandTabs(
375376
string $text,
@@ -379,7 +380,7 @@ public static function expandTabs(
379380
if (strpos($text, "\t") === false) {
380381
return $text;
381382
}
382-
$eol = Get::eol($text) ?: "\n";
383+
$eol = Get::eol($text) ?? "\n";
383384
$expanded = '';
384385
foreach (explode($eol, $text) as $i => $line) {
385386
!$i || $expanded .= $eol;
@@ -402,7 +403,11 @@ public static function expandTabs(
402403
}
403404

404405
/**
405-
* Expand leading tabs to spaces
406+
* Expand leading tabs in a string to spaces
407+
*
408+
* @param bool $preserveLine1 If `true`, tabs in the first line of `$text`
409+
* are not expanded.
410+
* @param int $column The starting column (1-based) of `$text`.
406411
*/
407412
public static function expandLeadingTabs(
408413
string $text,
@@ -413,7 +418,7 @@ public static function expandLeadingTabs(
413418
if (strpos($text, "\t") === false) {
414419
return $text;
415420
}
416-
$eol = Get::eol($text) ?: "\n";
421+
$eol = Get::eol($text) ?? "\n";
417422
$softTab = str_repeat(' ', $tabSize);
418423
$expanded = '';
419424
foreach (explode($eol, $text) as $i => $line) {
@@ -432,7 +437,7 @@ public static function expandLeadingTabs(
432437
if (!$parts) {
433438
break;
434439
}
435-
if ($part) {
440+
if ($part !== '') {
436441
$expanded .= "\t" . implode("\t", $parts);
437442
break;
438443
}

tests/unit/Toolkit/Utility/StrTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ public static function expandLeadingTabsProvider(): array
657657
[' a', "\ta", 8],
658658
[" \nabc\t", "\t\nabc\t", 4, false, 2],
659659
[" \n abc\t", "\t\n\tabc\t", 4, false, 2],
660+
[" 0\t1\t2\n 0\t1\t2", "\t0\t1\t2\n\t0\t1\t2", 4, false, 2],
660661
[
661662
<<<EOF
662663
abc\tde\tf\t\tg

0 commit comments

Comments
 (0)