From 36e02ea5fd7cd32ecf92db500f8b8a359a8aca05 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Thu, 3 Aug 2023 16:59:21 +0200 Subject: [PATCH] Improve interfaces tools --- CHANGELOG.md | 1 + Idna/{Idna.php => Converter.php} | 2 +- Idna/{IdnaTest.php => ConverterTest.php} | 16 ++++++++-------- Idna/ResultTest.php | 2 +- UriString.php | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) rename Idna/{Idna.php => Converter.php} (99%) rename Idna/{IdnaTest.php => ConverterTest.php} (82%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59c3170..96aaeeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All Notable changes to `League\Uri\Interfaces` will be documented in this file - New method to `UriInterface::toString` - New method to `UriInterface::toComponents` - `League\Uri\IPv4\Converter` class +- `League\Uri\Idna\Converter` class - `League\Uri\Idna\Error` class - `League\Uri\Idna\Option` class - `League\Uri\UriString` class diff --git a/Idna/Idna.php b/Idna/Converter.php similarity index 99% rename from Idna/Idna.php rename to Idna/Converter.php index 02e7f8c..c5176f8 100644 --- a/Idna/Idna.php +++ b/Idna/Converter.php @@ -24,7 +24,7 @@ /** * @see https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/uidna_8h.html */ -final class Idna +final class Converter { private const REGEXP_IDNA_PATTERN = '/[^\x20-\x7f]/'; private const MAX_DOMAIN_LENGTH = 253; diff --git a/Idna/IdnaTest.php b/Idna/ConverterTest.php similarity index 82% rename from Idna/IdnaTest.php rename to Idna/ConverterTest.php index 635e9e4..c045462 100644 --- a/Idna/IdnaTest.php +++ b/Idna/ConverterTest.php @@ -16,16 +16,16 @@ use PHPUnit\Framework\TestCase; /** - * @coversDefaultClass \League\Uri\Idna\Idna + * @coversDefaultClass \League\Uri\Idna\Converter */ -final class IdnaTest extends TestCase +final class ConverterTest extends TestCase { /** * @dataProvider invalidDomainProvider */ public function testToAsciiThrowsException(string $domain): void { - self::assertNotEmpty(Idna::toAscii($domain, Option::forIDNA2008Ascii())->errors()); + self::assertNotEmpty(Converter::toAscii($domain, Option::forIDNA2008Ascii())->errors()); } /** @@ -44,7 +44,7 @@ public static function invalidDomainProvider(): iterable public function testToUnicodeThrowsException(): void { - self::assertNotEmpty(Idna::toUnicode('xn--a-ecp.ru', Option::forIDNA2008Unicode())->errors()); + self::assertNotEmpty(Converter::toUnicode('xn--a-ecp.ru', Option::forIDNA2008Unicode())->errors()); } /** @@ -52,7 +52,7 @@ public function testToUnicodeThrowsException(): void */ public function testToIDN(string $domain, string $expectedDomain): void { - self::assertSame($expectedDomain, Idna::toUnicode($domain, Option::forIDNA2008Unicode())->domain()); + self::assertSame($expectedDomain, Converter::toUnicode($domain, Option::forIDNA2008Unicode())->domain()); } /** @@ -93,7 +93,7 @@ public static function toUnicodeProvider(): iterable */ public function testToAscii(string $domain, string $expectedDomain): void { - self::assertSame($expectedDomain, Idna::toAscii($domain, Option::forIDNA2008Ascii())->domain()); + self::assertSame($expectedDomain, Converter::toAscii($domain, Option::forIDNA2008Ascii())->domain()); } /** @@ -123,11 +123,11 @@ public static function toAsciiProvider(): iterable public function testExceptionThrownOnConversionToAsciiIfTheDomainIsTooLong(): void { - self::assertNotEmpty(Idna::toAscii(str_repeat('A', 255), Option::forIDNA2008Ascii())->errors()); + self::assertNotEmpty(Converter::toAscii(str_repeat('A', 255), Option::forIDNA2008Ascii())->errors()); } public function testExceptionThrownOnConversionToAsciiIfTheDomainLabelIsTooLong(): void { - self::assertNotEmpty(Idna::toAscii('aa'.str_repeat('A', 64), Option::forIDNA2008Ascii())->errors()); + self::assertNotEmpty(Converter::toAscii('aa'.str_repeat('A', 64), Option::forIDNA2008Ascii())->errors()); } } diff --git a/Idna/ResultTest.php b/Idna/ResultTest.php index b8891b7..7234188 100644 --- a/Idna/ResultTest.php +++ b/Idna/ResultTest.php @@ -33,7 +33,7 @@ public function testItCanBeInstantiatedFromArray(): void public function testInvalidSyntaxAfterIDNConversion(): void { - $result = Idna::toAscii('%00.com', Option::forIDNA2008Ascii()); + $result = Converter::toAscii('%00.com', Option::forIDNA2008Ascii()); self::assertTrue($result->hasErrors()); self::assertCount(1, $result->errors()); diff --git a/UriString.php b/UriString.php index d1dbe48..e934560 100644 --- a/UriString.php +++ b/UriString.php @@ -15,7 +15,7 @@ use League\Uri\Exceptions\SyntaxError; use League\Uri\Idna\ConversionFailed; -use League\Uri\Idna\Idna; +use League\Uri\Idna\Converter; use League\Uri\Idna\MissingSupport; use Stringable; use function array_merge; @@ -405,7 +405,7 @@ private static function filterRegisteredName(string $host): string throw new SyntaxError(sprintf('Host `%s` is invalid : the host is not a valid registered name', $host)); } - $result = Idna::toAscii($host); + $result = Converter::toAscii($host); if ($result->hasErrors()) { throw ConversionFailed::dueToError($host, $result); }