From 76e9c3bbf62ffead1f7522a0f1ab5a28616cbf7c Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 4 Sep 2023 15:38:43 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/voku/helper/UTF8.php | 26 ++++++++------------------ tests/ShimIconvTest.php | 23 +++++++++++------------ tests/Utf8GlobalNonStrictPart1Test.php | 10 ---------- tests/Utf8GlobalNonStrictPart2Test.php | 3 --- tests/Utf8GlobalNonStrictPart3Test.php | 1 - tests/Utf8GlobalPart1Test.php | 15 ++------------- tests/Utf8GlobalPart2Test.php | 3 --- tests/Utf8StrPadTest.php | 4 ++-- tests/Utf8SubstrReplaceTest.php | 1 - tests/Utf8ToAsciiTest.php | 1 - 10 files changed, 23 insertions(+), 64 deletions(-) diff --git a/src/voku/helper/UTF8.php b/src/voku/helper/UTF8.php index 837f0532..89225dec 100644 --- a/src/voku/helper/UTF8.php +++ b/src/voku/helper/UTF8.php @@ -628,7 +628,6 @@ public static function chr($code_point, string $encoding = 'UTF-8') } if ($code_point <= 0x80) { // only for "simple"-chars - if (self::$CHR === null) { self::$CHR = self::getData('chr'); } @@ -8177,7 +8176,6 @@ public static function str_split( \preg_match_all('/./us', $str, $return_array); $ret = $return_array[0] ?? []; } else { - // fallback $ret = []; @@ -9197,13 +9195,13 @@ public static function str_truncate( } return ( - (string) self::substr( - $str, - 0, - $length, - $encoding - ) - ) . $substring; + (string) self::substr( + $str, + 0, + $length, + $encoding + ) + ) . $substring; } /** @@ -12805,9 +12803,7 @@ public static function to_utf8_string(string $str, bool $decode_html_entity_to_u $c1 = $str[$i]; if ($c1 >= "\xC0") { // should be converted to UTF8, if it's not UTF8 already - if ($c1 <= "\xDF") { // looks like 2 bytes UTF8 - $c2 = $i + 1 >= $max ? "\x00" : $str[$i + 1]; if ($c2 >= "\x80" && $c2 <= "\xBF") { // yeah, almost sure it's UTF8 already @@ -12817,7 +12813,6 @@ public static function to_utf8_string(string $str, bool $decode_html_entity_to_u $buf .= self::to_utf8_convert_helper($c1); } } elseif ($c1 >= "\xE0" && $c1 <= "\xEF") { // looks like 3 bytes UTF8 - $c2 = $i + 1 >= $max ? "\x00" : $str[$i + 1]; $c3 = $i + 2 >= $max ? "\x00" : $str[$i + 2]; @@ -12828,7 +12823,6 @@ public static function to_utf8_string(string $str, bool $decode_html_entity_to_u $buf .= self::to_utf8_convert_helper($c1); } } elseif ($c1 >= "\xF0" && $c1 <= "\xF7") { // looks like 4 bytes UTF8 - $c2 = $i + 1 >= $max ? "\x00" : $str[$i + 1]; $c3 = $i + 2 >= $max ? "\x00" : $str[$i + 2]; $c4 = $i + 3 >= $max ? "\x00" : $str[$i + 3]; @@ -12840,14 +12834,11 @@ public static function to_utf8_string(string $str, bool $decode_html_entity_to_u $buf .= self::to_utf8_convert_helper($c1); } } else { // doesn't look like UTF8, but should be converted - $buf .= self::to_utf8_convert_helper($c1); } } elseif (($c1 & "\xC0") === "\x80") { // needs conversion - $buf .= self::to_utf8_convert_helper($c1); } else { // it doesn't need conversion - $buf .= $c1; } } @@ -13262,7 +13253,7 @@ public static function utf8_decode(string $str, bool $keep_utf8_chars = false): case "\xF0": ++$i; - // no break + // no break case "\xE0": $str[$j] = $no_char_found; @@ -13642,7 +13633,6 @@ private static function is_utf8_string(string $str, bool $strict = false) return false; } } elseif ((0xC0 & $in) === 0x80) { - // When mState is non-zero, we expect a continuation of the multi-octet // sequence diff --git a/tests/ShimIconvTest.php b/tests/ShimIconvTest.php index 451d034f..c376f39d 100644 --- a/tests/ShimIconvTest.php +++ b/tests/ShimIconvTest.php @@ -19,16 +19,16 @@ public function testIconv() // Native iconv() behavior varies between versions and OS for these two tests // See e.g. https://bugs.php.net/52211 if ( - !\defined('HHVM_VERSION') - && - ( - \PHP_VERSION_ID >= 50610 - || - (\PHP_VERSION_ID >= 50526 && \PHP_VERSION_ID < 50600) - || - '\\' === \DIRECTORY_SEPARATOR - ) - ) { + !\defined('HHVM_VERSION') + && + ( + \PHP_VERSION_ID >= 50610 + || + (\PHP_VERSION_ID >= 50526 && \PHP_VERSION_ID < 50600) + || + '\\' === \DIRECTORY_SEPARATOR + ) + ) { /** @noinspection PhpUsageOfSilenceOperatorInspection */ static::assertSame(\PHP_VERSION_ID >= 50400 ? false : 'n', @\iconv('UTF-8', 'ISO-8859-1', 'nœud')); static::assertSame('nud', \iconv('UTF-8', 'ISO-8859-1//IGNORE', 'nœud')); @@ -45,8 +45,7 @@ public function testIconv() static::assertSame('nud', @\iconv('UTF-8', 'ISO-8859-1//IGNORE', 'nœud')); } } else { - - // See e.g. https://bugs.php.net/52211 + // See e.g. https://bugs.php.net/52211 /** @noinspection PhpUndefinedConstantInspection */ if (\defined('HHVM_VERSION') && HHVM_VERSION_ID >= 30901) { /** @noinspection PhpUsageOfSilenceOperatorInspection */ diff --git a/tests/Utf8GlobalNonStrictPart1Test.php b/tests/Utf8GlobalNonStrictPart1Test.php index e687554b..dadc71cb 100644 --- a/tests/Utf8GlobalNonStrictPart1Test.php +++ b/tests/Utf8GlobalNonStrictPart1Test.php @@ -217,7 +217,6 @@ public function testChar() } for ($i = 0; $i < 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -959,7 +958,6 @@ public function testFileGetContents() // --- if (UTF8::mbstring_loaded()) { // only with "mbstring" - static::assertTrue(UTF8::is_binary_file(__DIR__ . '/fixtures/utf-16-be.txt')); $testString = UTF8::file_get_contents(__DIR__ . '/fixtures/utf-16-be.txt'); if (\method_exists(__CLASS__, 'assertStringContainsString')) { @@ -1012,7 +1010,6 @@ public function testFileGetContents() } if (UTF8::mbstring_loaded()) { // only with "mbstring" - $testString = UTF8::file_get_contents(__DIR__ . '/fixtures/utf-16-be.txt'); if (\method_exists(__CLASS__, 'assertStringContainsString')) { static::assertStringContainsString( @@ -1358,7 +1355,6 @@ public function testFixSimpleUtf8() ]; for ($i = 0; $i < 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -2614,7 +2610,6 @@ public function testNormalizeWhitespace() ]; for ($i = 0; $i < 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -2656,7 +2651,6 @@ public function testOrd() ]; for ($i = 0; $i < 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -2712,7 +2706,6 @@ public function testOrd() ]; for ($i = 0; $i < 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -3082,7 +3075,6 @@ public function testSplit() { $oldSupportArray = null; for ($i = 0; $i <= 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -3132,7 +3124,6 @@ public function testStrDetectEncoding() ]; for ($i = 0; $i <= 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -3690,7 +3681,6 @@ public function testStripWhitespace($expected, $str) public function testStripos() { for ($i = 0; $i <= 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { diff --git a/tests/Utf8GlobalNonStrictPart2Test.php b/tests/Utf8GlobalNonStrictPart2Test.php index 3af131d1..39bc0a02 100644 --- a/tests/Utf8GlobalNonStrictPart2Test.php +++ b/tests/Utf8GlobalNonStrictPart2Test.php @@ -92,7 +92,6 @@ public function testStrlen() ]; for ($i = 0; $i <= 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -282,7 +281,6 @@ public function testStrposInByte() public function testStrpos() { for ($i = 0; $i <= 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -366,7 +364,6 @@ public function testStrpos() // --- invalid UTF-8 if (UTF8::getSupportInfo('mbstring') === true) { // only with "mbstring" - static::assertSame(15, UTF8::strpos('ABC-ÖÄÜ-💩-' . "\xc3\x28" . '中文空白-中文空白' . "\xf0\x28\x8c\x28" . 'abc', '白')); if (Bootup::is_php('7.1')) { diff --git a/tests/Utf8GlobalNonStrictPart3Test.php b/tests/Utf8GlobalNonStrictPart3Test.php index 07d999fb..c892a6ea 100644 --- a/tests/Utf8GlobalNonStrictPart3Test.php +++ b/tests/Utf8GlobalNonStrictPart3Test.php @@ -451,7 +451,6 @@ public function testToUtf8V3() public function testTrim($input, $output) { for ($i = 0; $i <= 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { diff --git a/tests/Utf8GlobalPart1Test.php b/tests/Utf8GlobalPart1Test.php index c1bc72d3..39ae820c 100644 --- a/tests/Utf8GlobalPart1Test.php +++ b/tests/Utf8GlobalPart1Test.php @@ -211,7 +211,6 @@ public function testChar() } for ($i = 0; $i < 200; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -965,7 +964,6 @@ public function testFileGetContents() // --- if (UTF8::mbstring_loaded()) { // only with "mbstring" - static::assertTrue(UTF8::is_binary_file(__DIR__ . '/fixtures/utf-16-be.txt')); $testString = UTF8::file_get_contents(__DIR__ . '/fixtures/utf-16-be.txt'); static::assertStringContainsString( @@ -992,7 +990,6 @@ public function testFileGetContents() static::assertStringContainsString('Iñtërnâtiônàlizætiøn', $testString); if (UTF8::mbstring_loaded()) { // only with "mbstring" - $testString = UTF8::file_get_contents(__DIR__ . '/fixtures/utf-16-be.txt'); static::assertStringContainsString( '

Today’s Internet users are not the same users who were online a decade ago. There are better connections.', @@ -1069,7 +1066,6 @@ public function testFileGetContents() // --- if (UTF8::mbstring_loaded()) { // only with "mbstring" - static::assertTrue(UTF8::is_binary_file(__DIR__ . '/fixtures/utf-16-be.txt')); $testString = UTF8::file_get_contents(__DIR__ . '/fixtures/utf-16-be.txt'); static::assertContains( @@ -1096,7 +1092,6 @@ public function testFileGetContents() static::assertContains('Iñtërnâtiônàlizætiøn', $testString); if (UTF8::mbstring_loaded()) { // only with "mbstring" - $testString = UTF8::file_get_contents(__DIR__ . '/fixtures/utf-16-be.txt'); static::assertContains( '

Today’s Internet users are not the same users who were online a decade ago. There are better connections.', @@ -1354,7 +1349,6 @@ public function testFixSimpleUtf8() ]; for ($i = 0; $i < 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -2609,7 +2603,6 @@ public function testNormalizeWhitespace() ]; for ($i = 0; $i < 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -2651,7 +2644,6 @@ public function testOrd() ]; for ($i = 0; $i < 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -3131,7 +3123,6 @@ public function testSplit() { $oldSupportArray = null; for ($i = 0; $i <= 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -3181,7 +3172,6 @@ public function testStrDetectEncoding() ]; for ($i = 0; $i <= 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -3372,9 +3362,9 @@ public function testStrPad() static::assertSame('___中文空白___', UTF8::str_pad('中文空白', 10, '_', \STR_PAD_BOTH)); $toPad = ''; // 10 characters - $padding = 'ø__'; // 4 characters + $padding = 'ø__'; // 4 characters - static::assertSame($toPad . ' ', UTF8::str_pad($toPad, 20)); + static::assertSame($toPad . ' ', UTF8::str_pad($toPad, 20)); static::assertSame(' ' . $toPad, UTF8::str_pad($toPad, 20, ' ', \STR_PAD_LEFT)); static::assertSame(' ' . $toPad . ' ', UTF8::str_pad($toPad, 20, ' ', \STR_PAD_BOTH)); @@ -3861,7 +3851,6 @@ public function testStripWhitespace($expected, $str) public function testStripos() { for ($i = 0; $i <= 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { diff --git a/tests/Utf8GlobalPart2Test.php b/tests/Utf8GlobalPart2Test.php index 133dc58c..986f0f79 100644 --- a/tests/Utf8GlobalPart2Test.php +++ b/tests/Utf8GlobalPart2Test.php @@ -83,7 +83,6 @@ public function testStrlen() ]; for ($i = 0; $i <= 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -282,7 +281,6 @@ public function testStrposInByte() public function testStrpos() { for ($i = 0; $i <= 2; ++$i) { // keep this loop for simple performance tests - if ($i === 0) { $this->disableNativeUtf8Support(); } elseif ($i > 0) { @@ -346,7 +344,6 @@ public function testStrpos() // --- invalid UTF-8 if (UTF8::getSupportInfo('mbstring') === true) { // only with "mbstring" - static::assertSame(15, UTF8::strpos('ABC-ÖÄÜ-💩-' . "\xc3\x28" . '中文空白-中文空白' . "\xf0\x28\x8c\x28" . 'abc', '白')); if (Bootup::is_php('7.1')) { diff --git a/tests/Utf8StrPadTest.php b/tests/Utf8StrPadTest.php index b2aebb80..b35af5ef 100644 --- a/tests/Utf8StrPadTest.php +++ b/tests/Utf8StrPadTest.php @@ -16,9 +16,9 @@ final class Utf8StrPadTest extends \PHPUnit\Framework\TestCase public function testStrPad() { $toPad = ''; // 10 characters - $padding = 'ø__'; // 4 characters + $padding = 'ø__'; // 4 characters - static::assertSame($toPad . ' ', u::str_pad($toPad, 20)); + static::assertSame($toPad . ' ', u::str_pad($toPad, 20)); static::assertSame(' ' . $toPad, u::str_pad($toPad, 20, ' ', \STR_PAD_LEFT)); static::assertSame(' ' . $toPad . ' ', u::str_pad($toPad, 20, ' ', \STR_PAD_BOTH)); diff --git a/tests/Utf8SubstrReplaceTest.php b/tests/Utf8SubstrReplaceTest.php index 3effb188..3628cd1d 100644 --- a/tests/Utf8SubstrReplaceTest.php +++ b/tests/Utf8SubstrReplaceTest.php @@ -30,7 +30,6 @@ public function testEmptyString() public function testNegative() { for ($i = 0; $i < 2; ++$i) { // keep this loop for simple performance tests - $str = 'testing'; $replaced = \substr_replace($str, 'foo', 0, -2); static::assertSame($replaced, u::substr_replace($str, 'foo', 0, -2)); diff --git a/tests/Utf8ToAsciiTest.php b/tests/Utf8ToAsciiTest.php index acc942bb..8440233c 100644 --- a/tests/Utf8ToAsciiTest.php +++ b/tests/Utf8ToAsciiTest.php @@ -54,7 +54,6 @@ public function testToASCII() { $testsStrict = []; if (UTF8::intl_loaded()) { - // --- $testString = UTF8::file_get_contents(__DIR__ . '/fixtures/sample-unicode-chart.txt');