Skip to content

Commit d124eb9

Browse files
committed
Apply review
1 parent 301b845 commit d124eb9

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

src/Mbstring/Mbstring.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@
7373
final class Mbstring
7474
{
7575
public const MB_CASE_FOLD = \PHP_INT_MAX;
76-
76+
7777
private const SIMPLE_CASE_FOLD = [
7878
['µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE"],
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);
@@ -1025,7 +1017,7 @@ private static function mb_internal_trim(string $regex, string $string, ?string
10251017
}
10261018

10271019
$regexCharacter = preg_quote($characters ?? '', '/');
1028-
$regex = sprintf($regex, $regexCharacter, $regexCharacter);
1020+
$regex = sprintf('/'.$regex.'/', $regexCharacter, $regexCharacter);
10291021

10301022
if ('ASCII' === mb_detect_encoding($characters) && 'ASCII' === mb_detect_encoding($string) && !empty(array_intersect(str_split(self::CHARACTERS), str_split($string)))) {
10311023
$options = 'g';
@@ -1034,15 +1026,15 @@ private static function mb_internal_trim(string $regex, string $string, ?string
10341026
}
10351027

10361028
try {
1037-
$test = mb_ereg_replace($regex, "", $string, $options);
1029+
$test = preg_replace($regex, "", $string, $options);
10381030

10391031
if (null === $test) {
10401032
throw new \Exception();
10411033
}
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) {

tests/Mbstring/MbstringTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ public static function lcFirstDataProvider(): array
816816
*/
817817
public function testMbTrim(string $expected, string $string, ?string $characters = null, ?string $encoding = null): void
818818
{
819-
$this->assertSame($expected, mb_trim($string, $characters, $encoding));
819+
$this->assertEquals($expected, mb_trim($string, $characters, $encoding));
820820
}
821821

822822
/**
@@ -836,7 +836,7 @@ public function testMbLTrim(string $expected, string $string, ?string $character
836836
*/
837837
public function testMbRTrim(string $expected, string $string, ?string $characters = null, ?string $encoding = null): void
838838
{
839-
$this->assertSame($expected, mb_rtrim($string, $characters, $encoding));
839+
$this->assertEquals($expected, mb_rtrim($string, $characters, $encoding));
840840
}
841841

842842
public function testMbTrimException(): void
@@ -847,9 +847,9 @@ public function testMbTrimException(): void
847847

848848
public function testMbTrimEncoding(): void
849849
{
850-
$this->assertSame('', mb_convert_encoding(mb_trim("\x81\x40\x82\xa0\x81\x40", "\x81\x40", "SJIS"), "UTF-8", "SJIS"));
851-
$this->assertSame('226f575b', bin2hex(mb_ltrim(mb_convert_encoding("\u{FFFE}漢字", "UTF-16LE", "UTF-8"), mb_convert_encoding("\u{FFFE}\u{FEFF}", "UTF-16LE", "UTF-8"), "UTF-16LE")));
852-
$this->assertSame('6f225b57', bin2hex(mb_ltrim(mb_convert_encoding("\u{FEFF}漢字", "UTF-16BE", "UTF-8"), mb_convert_encoding("\u{FFFE}\u{FEFF}", "UTF-16BE", "UTF-8"), "UTF-16BE")));
850+
$this->assertEquals('', mb_convert_encoding(mb_trim("\x81\x40\x82\xa0\x81\x40", "\x81\x40", "SJIS"), "UTF-8", "SJIS"));
851+
$this->assertEquals('226f575b', bin2hex(mb_ltrim(mb_convert_encoding("\u{FFFE}漢字", "UTF-16LE", "UTF-8"), mb_convert_encoding("\u{FFFE}\u{FEFF}", "UTF-16LE", "UTF-8"), "UTF-16LE")));
852+
$this->assertEquals('6f225b57', bin2hex(mb_ltrim(mb_convert_encoding("\u{FEFF}漢字", "UTF-16BE", "UTF-8"), mb_convert_encoding("\u{FFFE}\u{FEFF}", "UTF-16BE", "UTF-8"), "UTF-16BE")));
853853
}
854854

855855
public function testMbTrimCharactersEncoding(): void

tests/Php84/Php84Test.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public static function arrayAllDataProvider(): array
190190
*/
191191
public function testMbTrim(string $expected, string $string, ?string $characters = null, ?string $encoding = null): void
192192
{
193-
$this->assertSame($expected, mb_trim($string, $characters, $encoding));
193+
$this->assertEquals($expected, mb_trim($string, $characters, $encoding));
194194
}
195195

196196
/**
@@ -210,7 +210,7 @@ public function testMbLTrim(string $expected, string $string, ?string $character
210210
*/
211211
public function testMbRTrim(string $expected, string $string, ?string $characters = null, ?string $encoding = null): void
212212
{
213-
$this->assertSame($expected, mb_rtrim($string, $characters, $encoding));
213+
$this->assertEquals($expected, mb_rtrim($string, $characters, $encoding));
214214
}
215215

216216
public function testMbTrimException(): void
@@ -221,9 +221,9 @@ public function testMbTrimException(): void
221221

222222
public function testMbTrimEncoding(): void
223223
{
224-
$this->assertSame('', mb_convert_encoding(mb_trim("\x81\x40\x82\xa0\x81\x40", "\x81\x40", "SJIS"), "UTF-8", "SJIS"));
225-
$this->assertSame('226f575b', bin2hex(mb_ltrim(mb_convert_encoding("\u{FFFE}漢字", "UTF-16LE", "UTF-8"), mb_convert_encoding("\u{FFFE}\u{FEFF}", "UTF-16LE", "UTF-8"), "UTF-16LE")));
226-
$this->assertSame('6f225b57', bin2hex(mb_ltrim(mb_convert_encoding("\u{FEFF}漢字", "UTF-16BE", "UTF-8"), mb_convert_encoding("\u{FFFE}\u{FEFF}", "UTF-16BE", "UTF-8"), "UTF-16BE")));
224+
$this->assertEquals('', mb_convert_encoding(mb_trim("\x81\x40\x82\xa0\x81\x40", "\x81\x40", "SJIS"), "UTF-8", "SJIS"));
225+
$this->assertEquals('226f575b', bin2hex(mb_ltrim(mb_convert_encoding("\u{FFFE}漢字", "UTF-16LE", "UTF-8"), mb_convert_encoding("\u{FFFE}\u{FEFF}", "UTF-16LE", "UTF-8"), "UTF-16LE")));
226+
$this->assertEquals('6f225b57', bin2hex(mb_ltrim(mb_convert_encoding("\u{FEFF}漢字", "UTF-16BE", "UTF-8"), mb_convert_encoding("\u{FFFE}\u{FEFF}", "UTF-16BE", "UTF-8"), "UTF-16BE")));
227227
}
228228

229229
public function testMbTrimCharactersEncoding(): void

0 commit comments

Comments
 (0)