Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jun 19, 2024
1 parent 0e4546d commit 41ef333
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 90 deletions.
6 changes: 3 additions & 3 deletions src/Intl/MessageFormatter/MessageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ private static function parseToken(array $token, array $values, $locale)
$offset = (int) trim(substr($selector, 7, $pos - 7));
$selector = trim(substr($selector, 1 + $pos, \strlen($selector)));
}
if (false === $message && 'other' === $selector ||
'=' === $selector[0] && (int) substr($selector, 1, \strlen($selector)) === $arg ||
'one' === $selector && 1 == $arg - $offset
if (false === $message && 'other' === $selector
|| '=' === $selector[0] && (int) substr($selector, 1, \strlen($selector)) === $arg
|| 'one' === $selector && 1 == $arg - $offset
) {
$message = implode(',', str_replace('#', $arg - $offset, $plural[$i]));
}
Expand Down
11 changes: 5 additions & 6 deletions src/Mbstring/Mbstring.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public static function mb_encoding_aliases($encoding)

public static function mb_check_encoding($var = null, $encoding = null)
{
if (PHP_VERSION_ID < 70200 && \is_array($var)) {
if (\PHP_VERSION_ID < 70200 && \is_array($var)) {
trigger_error('mb_check_encoding() expects parameter 1 to be string, array given', \E_USER_WARNING);

return null;
Expand All @@ -454,7 +454,6 @@ public static function mb_check_encoding($var = null, $encoding = null)
}

return true;

}

public static function mb_detect_encoding($str, $encodingList = null, $strict = false)
Expand Down Expand Up @@ -888,9 +887,9 @@ public static function mb_ucfirst(string $string, ?string $encoding = null): str
}

$firstChar = mb_substr($string, 0, 1, $encoding);
$firstChar = mb_convert_case($firstChar, MB_CASE_TITLE, $encoding);
$firstChar = mb_convert_case($firstChar, \MB_CASE_TITLE, $encoding);

return $firstChar . mb_substr($string, 1, null, $encoding);
return $firstChar.mb_substr($string, 1, null, $encoding);
}

public static function mb_lcfirst(string $string, ?string $encoding = null): string
Expand All @@ -902,9 +901,9 @@ public static function mb_lcfirst(string $string, ?string $encoding = null): str
}

$firstChar = mb_substr($string, 0, 1, $encoding);
$firstChar = mb_convert_case($firstChar, MB_CASE_LOWER, $encoding);
$firstChar = mb_convert_case($firstChar, \MB_CASE_LOWER, $encoding);

return $firstChar . mb_substr($string, 1, null, $encoding);
return $firstChar.mb_substr($string, 1, null, $encoding);
}

private static function getSubpart($pos, $part, $haystack, $encoding)
Expand Down
1 change: 1 addition & 0 deletions src/Php72/Php72.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public static function stream_isatty($stream)

if ('\\' === \DIRECTORY_SEPARATOR) {
$stat = @fstat($stream);

// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Php81/Resources/stubs/CURLStringFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __set(string $name, $value): void
}

if (is_object($value) ? !method_exists($value, '__toString') : !is_scalar($value)) {
throw new \TypeError('Cannot assign '.gettype($value).' to property CURLStringFile::$data of type string');
throw new TypeError('Cannot assign '.gettype($value).' to property CURLStringFile::$data of type string');
}

$this->name = 'data://application/octet-stream;base64,'.base64_encode($value);
Expand Down
6 changes: 3 additions & 3 deletions src/Php82/Php82.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ public static function ini_parse_quantity(string $value): int
while ($digits_consumed < $str_end && false !== strpos($ctype_space, $value[$digits_consumed])) {
++$digits_consumed;
}
if ($digits_consumed !== $str_end && ($value[$digits_consumed] === '+' || $value[$digits_consumed] === '-')) {
if ($digits_consumed !== $str_end && ('+' === $value[$digits_consumed] || '-' === $value[$digits_consumed])) {
++$digits_consumed;
}

if ($value[$digits_consumed] === '0') {
if ('0' === $value[$digits_consumed]) {
/* Value is just 0 */
if ($digits_consumed + 1 === $str_end) {
goto evaluation;
Expand All @@ -197,7 +197,7 @@ public static function ini_parse_quantity(string $value): int
case 'b':
case 'B':
$digits_consumed += 2;
break;
break;
}
}

Expand Down
30 changes: 15 additions & 15 deletions src/Php83/Php83.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ public static function str_increment(string $string): string
throw new \ValueError('str_increment(): Argument #1 ($string) cannot be empty');
}

if (!\preg_match("/^[a-zA-Z0-9]+$/", $string)) {
if (!preg_match('/^[a-zA-Z0-9]+$/', $string)) {
throw new \ValueError('str_increment(): Argument #1 ($string) must be composed only of alphanumeric ASCII characters');
}

if (\is_numeric($string)) {
if (is_numeric($string)) {
$offset = stripos($string, 'e');
if ($offset !== false) {
if (false !== $offset) {
$char = $string[$offset];
$char++;
++$char;
$string[$offset] = $char;
$string++;
++$string;

switch ($string[$offset]) {
case 'f':
Expand Down Expand Up @@ -130,64 +130,64 @@ public static function str_decrement(string $string): string
throw new \ValueError('str_decrement(): Argument #1 ($string) cannot be empty');
}

if (!\preg_match("/^[a-zA-Z0-9]+$/", $string)) {
if (!preg_match('/^[a-zA-Z0-9]+$/', $string)) {
throw new \ValueError('str_decrement(): Argument #1 ($string) must be composed only of alphanumeric ASCII characters');
}

if (\preg_match('/\A(?:0[aA0]?|[aA])\z/', $string)) {
if (preg_match('/\A(?:0[aA0]?|[aA])\z/', $string)) {
throw new \ValueError(sprintf('str_decrement(): Argument #1 ($string) "%s" is out of decrement range', $string));
}

if (!\in_array(substr($string, -1), ['A', 'a', '0'], true)) {
return join('', array_slice(str_split($string), 0, -1)) . chr(ord(substr($string, -1)) - 1);
return implode('', \array_slice(str_split($string), 0, -1)).\chr(\ord(substr($string, -1)) - 1);
}

$carry = '';
$decremented = '';

for ($i = strlen($string) - 1; $i >= 0; $i--) {
for ($i = \strlen($string) - 1; $i >= 0; --$i) {
$char = $string[$i];

switch ($char) {
case 'A':
if ('' !== $carry) {
$decremented = $carry . $decremented;
$decremented = $carry.$decremented;
$carry = '';
}
$carry = 'Z';

break;
case 'a':
if ('' !== $carry) {
$decremented = $carry . $decremented;
$decremented = $carry.$decremented;
$carry = '';
}
$carry = 'z';

break;
case '0':
if ('' !== $carry) {
$decremented = $carry . $decremented;
$decremented = $carry.$decremented;
$carry = '';
}
$carry = '9';

break;
case '1':
if ('' !== $carry) {
$decremented = $carry . $decremented;
$decremented = $carry.$decremented;
$carry = '';
}

break;
default:
if ('' !== $carry) {
$decremented = $carry . $decremented;
$decremented = $carry.$decremented;
$carry = '';
}

if (!\in_array($char, ['A', 'a', '0'], true)) {
$decremented = chr(ord($char) - 1) . $decremented;
$decremented = \chr(\ord($char) - 1).$decremented;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Php84/Php84.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public static function mb_ucfirst(string $string, ?string $encoding = null): str
}

$firstChar = mb_substr($string, 0, 1, $encoding);
$firstChar = mb_convert_case($firstChar, MB_CASE_TITLE, $encoding);
$firstChar = mb_convert_case($firstChar, \MB_CASE_TITLE, $encoding);

return $firstChar . mb_substr($string, 1, null, $encoding);
return $firstChar.mb_substr($string, 1, null, $encoding);
}

public static function mb_lcfirst(string $string, ?string $encoding = null): string
Expand All @@ -59,9 +59,9 @@ public static function mb_lcfirst(string $string, ?string $encoding = null): str
}

$firstChar = mb_substr($string, 0, 1, $encoding);
$firstChar = mb_convert_case($firstChar, MB_CASE_LOWER, $encoding);
$firstChar = mb_convert_case($firstChar, \MB_CASE_LOWER, $encoding);

return $firstChar . mb_substr($string, 1, null, $encoding);
return $firstChar.mb_substr($string, 1, null, $encoding);
}

public static function array_find(array $array, callable $callback)
Expand Down
1 change: 0 additions & 1 deletion src/Php84/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
return;
}


if (!function_exists('mb_ucfirst')) {
function mb_ucfirst($string, ?string $encoding = null): string { return p\Php84::mb_ucfirst($string, $encoding); }
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Iconv/IconvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function testIconvSubstr()

/**
* @covers \Symfony\Polyfill\Iconv\Iconv::iconv_substr
*
* @requires PHP < 8
*/
public function testIconvSubstrReturnsFalsePrePHP8()
Expand All @@ -84,6 +85,7 @@ public function testIconvSubstrReturnsFalsePrePHP8()

/**
* @covers \Symfony\Polyfill\Iconv\Iconv::iconv_substr
*
* @requires PHP 8
*/
public function testIconvSubstrReturnsEmptyPostPHP8()
Expand Down Expand Up @@ -169,6 +171,7 @@ public function testIconvMimeDecodeHeaders()
/**
* @covers \Symfony\Polyfill\Iconv\Iconv::iconv_get_encoding
* @covers \Symfony\Polyfill\Iconv\Iconv::iconv_set_encoding
*
* @group legacy
*/
public function testIconvGetEncoding()
Expand Down
2 changes: 2 additions & 0 deletions tests/Intl/Grapheme/GraphemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function testGraphemeSubstr()

/**
* @covers \Symfony\Polyfill\Intl\Grapheme\Grapheme::grapheme_substr
*
* @requires PHP < 8
*/
public function testGraphemeSubstrReturnsFalsePrePHP8()
Expand All @@ -138,6 +139,7 @@ public function testGraphemeSubstrReturnsFalsePrePHP8()

/**
* @covers \Symfony\Polyfill\Intl\Grapheme\Grapheme::grapheme_substr
*
* @requires PHP 8
*/
public function testGraphemeSubstrReturnsEmptyPostPHP8()
Expand Down
1 change: 1 addition & 0 deletions tests/Intl/Icu/Verification/IntlDateFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function testDateAndTimeType($timestamp, $datetype, $timetype, $expected)

/**
* @requires PHP 8
*
* @dataProvider relativeDateTypeProvider
*/
public function testRelativeDateType($timestamp, $datetype, $timetype, $expected)
Expand Down
20 changes: 12 additions & 8 deletions tests/Intl/Idn/IdnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Polyfill\Tests\Intl\Idn;

use PHPUnit\Framework\TestCase;
use RuntimeException;
use Symfony\Polyfill\Intl\Idn\Idn;

/**
Expand Down Expand Up @@ -198,7 +197,9 @@ public function testToAsciiTransitional($source, $toUnicode, $toUnicodeStatus, $

/**
* @requires PHP < 8
*
* @group legacy
*
* @dataProvider domainNamesProvider
*/
public function testEncode2003($decoded, $encoded)
Expand All @@ -218,7 +219,9 @@ public function testEncodeInvalid($decoded)

/**
* @requires PHP < 8
*
* @group legacy
*
* @dataProvider domainNamesProvider
*/
public function testDecode2003($decoded, $encoded)
Expand Down Expand Up @@ -275,7 +278,9 @@ public function testUppercaseUTS46($decoded, $ascii, $encoded)

/**
* @requires PHP < 8
*
* @group legacy
*
* @dataProvider domainNamesProvider
*/
public function testEncodePhp53($decoded, $encoded)
Expand All @@ -285,7 +290,7 @@ public function testEncodePhp53($decoded, $encoded)
}

/**
* IDNA 15.1.0 revision 31
* IDNA 15.1.0 revision 31.
*
* This tests the change in "Section 4 Processing step 1. Map" which conditionally maps U+1E9E capital sharp s to
* "ss" if Transitional_Processing is used.
Expand All @@ -299,7 +304,7 @@ public function testCapitalSharpSProcessing($input, $expected, $flags)
}

/**
* IDNA 15.1.0 revision 31
* IDNA 15.1.0 revision 31.
*
* This tests the additional validity check in "Section 4.1 Validity Criteria Processing step 4", which is used to
* disallow labels that do not round trip.
Expand All @@ -312,14 +317,14 @@ public function testLabelsThatDoNotRoundTripAreDisallowed()
}

/**
* IDNA 15.1.0 revision 31
* IDNA 15.1.0 revision 31.
*
* This tests the the additional condition in "Section 4 Processing step 4.1" where a label that starts with "xn--"
* and contains a non-ASCII codepoint records an error and the processing steps continue with the next label.
*/
public function testLabelStartingWithPunycodePrefixWithNonAsciiCharacterRecordsErrorAndIsSkipped()
{
\idn_to_utf8('xn--🌈.xn--fa-hia.de', \IDNA_DEFAULT, \INTL_IDNA_VARIANT_UTS46, $info);
idn_to_utf8('xn--🌈.xn--fa-hia.de', \IDNA_DEFAULT, \INTL_IDNA_VARIANT_UTS46, $info);
$this->assertSame(\IDNA_ERROR_PUNYCODE, \IDNA_ERROR_PUNYCODE & $info['errors']);
$this->assertSame('xn--🌈.faß.de', $info['result']);
}
Expand All @@ -332,7 +337,6 @@ public static function captialSharpSProvider()
];
}


public static function domainNamesProvider()
{
return [
Expand Down Expand Up @@ -489,11 +493,11 @@ private static function resolveErrorCodes($statusCodes, $inherit)
$matchCount = preg_match_all('/[PVUABCX][0-9](?:_[0-9])?/', $statusCodes, $matches);

if (\PREG_NO_ERROR !== preg_last_error()) {
throw new RuntimeException();
throw new \RuntimeException();
}

if (0 === $matchCount) {
throw new RuntimeException();
throw new \RuntimeException();
}

$errors = [];
Expand Down
3 changes: 2 additions & 1 deletion tests/Intl/Normalizer/NormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @author Nicolas Grekas <[email protected]>
*
* @covers \Symfony\Polyfill\Intl\Normalizer\Normalizer::<!public>
*
* @requires extension intl
*/
class NormalizerTest extends TestCase
Expand Down Expand Up @@ -68,7 +69,7 @@ public function testNormalize()
{
$c = in::normalize('déjà', pn::NFC).in::normalize('훈쇼™', pn::NFD);
if (\PHP_VERSION_ID < 70300) {
$this->assertSame($c, normalizer_normalize($c, \Normalizer::NONE));
$this->assertSame($c, normalizer_normalize($c, in::NONE));
}

$c = 'déjà 훈쇼™';
Expand Down
Loading

0 comments on commit 41ef333

Please sign in to comment.