Skip to content

Commit 848bc23

Browse files
committed
Symplify code
1 parent 6cf7118 commit 848bc23

File tree

5 files changed

+9
-18
lines changed

5 files changed

+9
-18
lines changed

src/Domain.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,14 @@ private function parseValue($domain): ?string
159159

160160
private function domainToAscii(string $domain): string
161161
{
162-
$option = IntlIdna::IDNA2008_ASCII_OPTIONS;
163-
if (self::IDNA_2003 === $this->type) {
164-
$option = IntlIdna::IDNA2003_ASCII_OPTIONS;
165-
}
162+
$option = self::IDNA_2003 === $this->type ? IntlIdna::IDNA2003_ASCII : IntlIdna::IDNA2008_ASCII;
166163

167164
return IntlIdna::toAscii($domain, $option)->result();
168165
}
169166

170167
private function domainToUnicode(string $domain): string
171168
{
172-
$option = IntlIdna::IDNA2008_UNICODE_OPTIONS;
173-
if (self::IDNA_2003 === $this->type) {
174-
$option = IntlIdna::IDNA2003_UNICODE_OPTIONS;
175-
}
169+
$option = self::IDNA_2003 === $this->type ? IntlIdna::IDNA2003_UNICODE : IntlIdna::IDNA2008_UNICODE;
176170

177171
return IntlIdna::toUnicode($domain, $option)->result();
178172
}

src/RootZoneDatabase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use JsonSerializable;
1212

1313
/**
14-
* @extends IteratorAggregate<EffectiveTopLevelDomain>
14+
* @extends IteratorAggregate<string>
1515
*/
1616
interface RootZoneDatabase extends Countable, DomainNameResolver, IteratorAggregate, JsonSerializable
1717
{
@@ -36,7 +36,7 @@ public function count(): int;
3636
public function isEmpty(): bool;
3737

3838
/**
39-
* @return Iterator<EffectiveTopLevelDomain>
39+
* @return Iterator<string>
4040
*/
4141
public function getIterator(): Iterator;
4242

src/Rules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private static function addRule(array $list, array $ruleParts): array
162162
try {
163163
/** @var string $line */
164164
$line = array_pop($ruleParts);
165-
$rule = IntlIdna::toAscii($line, IntlIdna::IDNA2008_ASCII_OPTIONS)->result();
165+
$rule = IntlIdna::toAscii($line, IntlIdna::IDNA2008_ASCII)->result();
166166
} catch (CannotProcessHost $exception) {
167167
throw UnableToLoadPublicSuffixList::dueToInvalidRule($line ?? null, $exception);
168168
}

src/TopLevelDomains.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private static function extractHeader(string $content): array
166166
private static function extractRootZone(string $content): string
167167
{
168168
try {
169-
$tld = Suffix::fromIANA($content)->toAscii();
169+
$tld = Suffix::fromIANA($content);
170170
} catch (CannotProcessHost $exception) {
171171
throw UnableToLoadRootZoneDatabase::dueToInvalidRootZoneDomain($content, $exception);
172172
}
@@ -221,12 +221,12 @@ public function isEmpty(): bool
221221
}
222222

223223
/**
224-
* @return Iterator<EffectiveTopLevelDomain>
224+
* @return Iterator<string>
225225
*/
226226
public function getIterator(): Iterator
227227
{
228228
foreach ($this->records as $tld) {
229-
yield Suffix::fromIANA($tld)->toAscii();
229+
yield $tld;
230230
}
231231
}
232232

@@ -290,7 +290,7 @@ private function containsTopLevelDomain(DomainName $domain): bool
290290
{
291291
$label = $domain->toAscii()->label(0);
292292
foreach ($this as $tld) {
293-
if ($tld->value() === $label) {
293+
if ($tld === $label) {
294294
return true;
295295
}
296296
}

src/TopLevelDomainsTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ public function testGetterProperties(): void
191191
);
192192
self::assertFalse($topLevelDomains->isEmpty());
193193
self::assertArrayHasKey('lastUpdated', $topLevelDomains->jsonSerialize());
194-
foreach ($topLevelDomains as $tld) {
195-
self::assertInstanceOf(Suffix::class, $tld);
196-
}
197194
}
198195

199196
/**

0 commit comments

Comments
 (0)