Skip to content

Commit 3130723

Browse files
committed
Improve internal codebase
1 parent e9eb70f commit 3130723

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All Notable changes to `PHP Domain Parser` starting from the **5.x** series will
1212

1313
- Using PHPUnit 10
1414
- `Domain` decorates the new `RegisteredName` class [#347](https://github.com/jeremykendall/php-domain-parser/issues/347)
15+
- `Host::withoutLabel` works without arguments.
1516

1617
### Deprecated
1718

src/DomainTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@ public function testwithoutLabelWorksWithMultipleKeys(): void
395395
self::assertNull(Domain::fromIDNA2008('www.example.com')->withoutLabel(0, 1, 2)->value());
396396
}
397397

398+
public function testWithoutLabelWorksWithoutArgument(): void
399+
{
400+
$domain = Domain::fromIDNA2008('www.example.com');
401+
402+
self::assertSame($domain, $domain->withoutLabel());
403+
}
404+
398405
#[DataProvider('resolveCustomIDNAOptionsProvider')]
399406
public function testResolveWorksWithCustomIDNAOptions(
400407
string $domainName,

src/RegisteredName.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,11 @@ public static function fromIDNA2008(DomainNameProvider|Host|Stringable|string|in
8181
*/
8282
private function parseDomain(DomainNameProvider|Host|Stringable|string|int|null $domain): ?string
8383
{
84-
if ($domain instanceof DomainNameProvider) {
85-
$domain = $domain->domain();
86-
}
87-
88-
if ($domain instanceof Host) {
89-
return $this->parseValue($domain->toUnicode()->value());
90-
}
91-
92-
return $this->parseValue($domain);
84+
return $this->parseValue(match (true) {
85+
$domain instanceof DomainNameProvider => $domain->domain()->value(),
86+
$domain instanceof Host => $domain->toUnicode()->value(),
87+
default => $domain,
88+
});
9389
}
9490

9591
/**

0 commit comments

Comments
 (0)