Skip to content

Commit 476cfd6

Browse files
committed
Apply review
1 parent 301b845 commit 476cfd6

File tree

5 files changed

+18
-25
lines changed

5 files changed

+18
-25
lines changed

src/Mbstring/Mbstring.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ final class Mbstring
7979
['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι'],
8080
];
8181

82+
private const CHARACTERS = " \f\n\r\t\v\x00\u{00A0}\u{1680}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}\u{0085}\u{180E}";
83+
8284
private static $encodingList = ['ASCII', 'UTF-8'];
8385
private static $language = 'neutral';
8486
private static $internalEncoding = 'UTF-8';
85-
private const CHARACTERS = " \f\n\r\t\v\x00\u{00A0}\u{1680}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}\u{0085}\u{180E}";
8687

8788
public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null)
8889
{
@@ -1005,16 +1006,7 @@ private static function mb_internal_trim(string $regex, string $string, ?string
10051006
$encoding = mb_internal_encoding();
10061007
}
10071008

1008-
try {
1009-
$validEncoding = @mb_check_encoding('', $encoding);
1010-
} catch (\ValueError $e) {
1011-
throw new \ValueError(sprintf('%s(): Argument #3 ($encoding) must be a valid encoding, "%s" given.', debug_backtrace()[1]['function'], $encoding));
1012-
}
1013-
1014-
// BC for PHP 7.3 and lower
1015-
if (!$validEncoding) {
1016-
throw new \ValueError(sprintf('%s(): Argument #3 ($encoding) must be a valid encoding, "%s" given.', debug_backtrace()[1]['function'], $encoding));
1017-
}
1009+
self::assertEncoding($encoding, debug_backtrace()[1]['function'].'(): Argument #3 ($encoding) must be a valid encoding, "%s" given.');
10181010

10191011
if ('' === $characters) {
10201012
return null === $encoding ? $string : mb_convert_encoding($string, $encoding);
@@ -1042,7 +1034,7 @@ private static function mb_internal_trim(string $regex, string $string, ?string
10421034

10431035
return $test;
10441036
} catch (\Exception $e) {
1045-
return preg_replace(sprintf('/%s/', $regex), "", $string);
1037+
return preg_replace('/'.$regex.'/', "", $string);
10461038
}
10471039
}
10481040

src/Php84/Php84.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
final class Php84
2121
{
2222
private const CHARACTERS = " \f\n\r\t\v\x00\u{00A0}\u{1680}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}\u{0085}\u{180E}";
23+
2324
public static function mb_ucfirst(string $string, ?string $encoding = null): string
2425
{
2526
if (null === $encoding) {

src/Php84/bootstrap.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ function array_any(array $array, callable $callback): bool { return p\Php84::arr
3939
function array_all(array $array, callable $callback): bool { return p\Php84::array_all($array, $callback); }
4040
}
4141

42-
if (!function_exists('mb_trim')) {
42+
if (!function_exists('mb_trim') && extension_loaded('mbstring')) {
4343
function mb_trim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Php84::mb_trim($string, $characters, $encoding); }
4444
}
4545

46-
if (!function_exists('mb_ltrim')) {
46+
if (!function_exists('mb_ltrim') && extension_loaded('mbstring')) {
4747
function mb_ltrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Php84::mb_ltrim($string, $characters, $encoding); }
4848
}
4949

50-
if (!function_exists('mb_rtrim')) {
50+
if (!function_exists('mb_rtrim') && extension_loaded('mbstring')) {
5151
function mb_rtrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Php84::mb_rtrim($string, $characters, $encoding); }
5252
}

tests/Mbstring/MbstringTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ public function testMbTrim(string $expected, string $string, ?string $characters
826826
*/
827827
public function testMbLTrim(string $expected, string $string, ?string $characters = null, ?string $encoding = null): void
828828
{
829-
$this->assertEquals($expected, mb_ltrim($string, $characters, $encoding));
829+
$this->assertSame($expected, mb_ltrim($string, $characters, $encoding));
830830
}
831831

832832
/**
@@ -856,15 +856,15 @@ public function testMbTrimCharactersEncoding(): void
856856
{
857857
$strUtf8 = "\u{3042}\u{3000}";
858858

859-
$this->assertEquals(1, mb_strlen(mb_trim($strUtf8)));
860-
$this->assertEquals(1, mb_strlen(mb_trim($strUtf8, null, 'UTF-8')));
859+
$this->assertSame(1, mb_strlen(mb_trim($strUtf8)));
860+
$this->assertSame(1, mb_strlen(mb_trim($strUtf8, null, 'UTF-8')));
861861

862862
$old = mb_internal_encoding();
863863
mb_internal_encoding('Shift_JIS');
864864
$strSjis = mb_convert_encoding($strUtf8, 'Shift_JIS', 'UTF-8');
865865

866-
$this->assertEquals(1, mb_strlen(mb_trim($strSjis)));
867-
$this->assertEquals(1, mb_strlen(mb_trim($strSjis, null, 'Shift_JIS')));
866+
$this->assertSame(1, mb_strlen(mb_trim($strSjis)));
867+
$this->assertSame(1, mb_strlen(mb_trim($strSjis, null, 'Shift_JIS')));
868868
mb_internal_encoding($old);
869869
}
870870

tests/Php84/Php84Test.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function testMbTrim(string $expected, string $string, ?string $characters
200200
*/
201201
public function testMbLTrim(string $expected, string $string, ?string $characters = null, ?string $encoding = null): void
202202
{
203-
$this->assertEquals($expected, mb_ltrim($string, $characters, $encoding));
203+
$this->assertSame($expected, mb_ltrim($string, $characters, $encoding));
204204
}
205205

206206
/**
@@ -230,15 +230,15 @@ public function testMbTrimCharactersEncoding(): void
230230
{
231231
$strUtf8 = "\u{3042}\u{3000}";
232232

233-
$this->assertEquals(1, mb_strlen(mb_trim($strUtf8)));
234-
$this->assertEquals(1, mb_strlen(mb_trim($strUtf8, null, 'UTF-8')));
233+
$this->assertSame(1, mb_strlen(mb_trim($strUtf8)));
234+
$this->assertSame(1, mb_strlen(mb_trim($strUtf8, null, 'UTF-8')));
235235

236236
$old = mb_internal_encoding();
237237
mb_internal_encoding('Shift_JIS');
238238
$strSjis = mb_convert_encoding($strUtf8, 'Shift_JIS', 'UTF-8');
239239

240-
$this->assertEquals(1, mb_strlen(mb_trim($strSjis)));
241-
$this->assertEquals(1, mb_strlen(mb_trim($strSjis, null, 'Shift_JIS')));
240+
$this->assertSame(1, mb_strlen(mb_trim($strSjis)));
241+
$this->assertSame(1, mb_strlen(mb_trim($strSjis, null, 'Shift_JIS')));
242242
mb_internal_encoding($old);
243243
}
244244

0 commit comments

Comments
 (0)