Skip to content

Commit d56106c

Browse files
committed
Improve type casting
1 parent 8ae5ef6 commit d56106c

File tree

5 files changed

+7
-48
lines changed

5 files changed

+7
-48
lines changed

src/DomainTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
use PHPUnit\Framework\Attributes\DataProvider;
88
use PHPUnit\Framework\TestCase;
9-
use stdClass;
10-
use TypeError;
119

1210
final class DomainTest extends TestCase
1311
{
@@ -290,12 +288,6 @@ public static function withLabelWorksProvider(): iterable
290288
];
291289
}
292290

293-
public function testWithLabelFailsWithTypeError(): void
294-
{
295-
$this->expectException(TypeError::class);
296-
Domain::fromIDNA2008('example.com')->withLabel(1, new stdClass()); /* @phpstan-ignore-line */
297-
}
298-
299291
public function testWithLabelFailsWithInvalidKey(): void
300292
{
301293
$this->expectException(SyntaxError::class);

src/ResolvedDomainTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
use PHPUnit\Framework\Attributes\DataProvider;
88
use PHPUnit\Framework\TestCase;
9-
use TypeError;
10-
11-
use function date_create;
129

1310
final class ResolvedDomainTest extends TestCase
1411
{
@@ -301,13 +298,6 @@ public function testItCanThrowsDuringSubDomainChangesIfTheSubDomainIsTheEmptyStr
301298
ResolvedDomain::fromICANN('www.example.com', 1)->withSubDomain('');
302299
}
303300

304-
public function testItCanThrowsDuringSubDomainChangesIfTheSubDomainIsNotStringable(): void
305-
{
306-
$this->expectException(TypeError::class);
307-
308-
ResolvedDomain::fromICANN('www.example.com', 1)->withSubDomain(date_create()); /* @phpstan-ignore-line */
309-
}
310-
311301
#[DataProvider('withPublicSuffixWorksProvider')]
312302
public function testItCanChangeItsSuffix(
313303
ResolvedDomain $domain,

src/Rules.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,7 @@ public static function __set_state(array $properties): self
152152
return new self($properties['rules']);
153153
}
154154

155-
/**
156-
* @param int|DomainNameProvider|Host|string|Stringable|null $host a type that supports instantiating a Domain from.
157-
*/
158-
public function resolve($host): ResolvedDomainName
155+
public function resolve(DomainNameProvider|Host|Stringable|string|int|null $host): ResolvedDomainName
159156
{
160157
try {
161158
return $this->getCookieDomain($host);
@@ -166,10 +163,7 @@ public function resolve($host): ResolvedDomainName
166163
}
167164
}
168165

169-
/**
170-
* @param int|DomainNameProvider|Host|string|Stringable|null $host the domain value
171-
*/
172-
public function getCookieDomain($host): ResolvedDomainName
166+
public function getCookieDomain(DomainNameProvider|Host|Stringable|string|int|null $host): ResolvedDomainName
173167
{
174168
$domain = $this->validateDomain($host);
175169
[$suffixLength, $section] = $this->resolveSuffix($domain->withoutRootLabel(), self::UNKNOWN_DOMAINS);
@@ -181,10 +175,7 @@ public function getCookieDomain($host): ResolvedDomainName
181175
};
182176
}
183177

184-
/**
185-
* @param int|DomainNameProvider|Host|string|Stringable|null $host a type that supports instantiating a Domain from.
186-
*/
187-
public function getICANNDomain($host): ResolvedDomainName
178+
public function getICANNDomain(DomainNameProvider|Host|Stringable|string|int|null $host): ResolvedDomainName
188179
{
189180
$domain = $this->validateDomain($host);
190181
[$suffixLength, $section] = $this->resolveSuffix($domain, self::ICANN_DOMAINS);
@@ -195,10 +186,7 @@ public function getICANNDomain($host): ResolvedDomainName
195186
return ResolvedDomain::fromICANN($domain, $suffixLength);
196187
}
197188

198-
/**
199-
* @param int|DomainNameProvider|Host|string|Stringable|null $host a type that supports instantiating a Domain from.
200-
*/
201-
public function getPrivateDomain($host): ResolvedDomainName
189+
public function getPrivateDomain(DomainNameProvider|Host|Stringable|string|int|null $host): ResolvedDomainName
202190
{
203191
$domain = $this->validateDomain($host);
204192
[$suffixLength, $section] = $this->resolveSuffix($domain, self::PRIVATE_DOMAINS);
@@ -215,7 +203,7 @@ public function getPrivateDomain($host): ResolvedDomainName
215203
* @throws SyntaxError If the domain is invalid
216204
* @throws UnableToResolveDomain If the domain can not be resolved
217205
*/
218-
private function validateDomain(int|DomainNameProvider|Host|string|Stringable|null $domain): DomainName
206+
private function validateDomain(DomainNameProvider|Host|Stringable|string|int|null $domain): DomainName
219207
{
220208
if ($domain instanceof DomainNameProvider) {
221209
$domain = $domain->domain();

src/RulesTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use PHPUnit\Framework\Attributes\DataProvider;
88
use PHPUnit\Framework\TestCase;
9-
use TypeError;
109

1110
use function array_fill;
1211
use function dirname;
@@ -67,13 +66,6 @@ public function testNullWillReturnNullDomain(): void
6766
self::assertFalse($domain->suffix()->isKnown());
6867
}
6968

70-
public function testThrowsTypeErrorOnWrongInput(): void
71-
{
72-
$this->expectException(TypeError::class);
73-
74-
self::$rules->resolve(date_create()); /* @phpstan-ignore-line */
75-
}
76-
7769
public function testIsSuffixValidFalse(): void
7870
{
7971
$domain = self::$rules->resolve('www.example.faketld');

src/TopLevelDomains.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ public function getIterator(): Iterator
164164
yield from array_keys($this->records);
165165
}
166166

167-
/**
168-
* @param int|DomainNameProvider|Host|string|Stringable|null $host a type that supports instantiating a Domain from.
169-
*/
170-
public function resolve($host): ResolvedDomainName
167+
public function resolve(DomainNameProvider|Host|Stringable|string|int|null $host): ResolvedDomainName
171168
{
172169
try {
173170
$domain = $this->validateDomain($host);
@@ -188,7 +185,7 @@ public function resolve($host): ResolvedDomainName
188185
* @throws SyntaxError If the domain is invalid
189186
* @throws UnableToResolveDomain If the domain can not be resolved
190187
*/
191-
private function validateDomain(int|DomainNameProvider|Host|string|Stringable|null $domain): DomainName
188+
private function validateDomain(DomainNameProvider|Host|Stringable|string|int|null $domain): DomainName
192189
{
193190
if ($domain instanceof DomainNameProvider) {
194191
$domain = $domain->domain();

0 commit comments

Comments
 (0)