Skip to content

Commit d13344c

Browse files
committed
fix #234 remove getter for both options at once
1 parent 23052bc commit d13344c

File tree

6 files changed

+104
-41
lines changed

6 files changed

+104
-41
lines changed

src/Domain.php

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public function toAscii()
421421
return $this;
422422
}
423423

424-
return new self($domain, $this->publicSuffix, ...$this->getIDNAOptions());
424+
return new self($domain, $this->publicSuffix, $this->getAsciiIDNAOption(), $this->getUnicodeIDNAOption());
425425
}
426426

427427
/**
@@ -436,7 +436,8 @@ public function toUnicode()
436436
return new self(
437437
$this->idnToUnicode($this->domain, $this->unicodeIDNAOption),
438438
$this->publicSuffix,
439-
...$this->getIDNAOptions()
439+
$this->getAsciiIDNAOption(),
440+
$this->getUnicodeIDNAOption()
440441
);
441442
}
442443

@@ -458,15 +459,20 @@ public function toUnicode()
458459
public function resolve($publicSuffix): self
459460
{
460461
if (!$publicSuffix instanceof PublicSuffix) {
461-
$publicSuffix = new PublicSuffix($publicSuffix, '', ...$this->getIDNAOptions());
462+
$publicSuffix = new PublicSuffix(
463+
$publicSuffix,
464+
'',
465+
$this->getAsciiIDNAOption(),
466+
$this->getUnicodeIDNAOption()
467+
);
462468
}
463469

464470
$publicSuffix = $this->normalize($publicSuffix);
465471
if ($this->publicSuffix == $publicSuffix) {
466472
return $this;
467473
}
468474

469-
return new self($this->domain, $publicSuffix, ...$this->getIDNAOptions());
475+
return new self($this->domain, $publicSuffix, $this->getAsciiIDNAOption(), $this->getUnicodeIDNAOption());
470476
}
471477

472478
/**
@@ -485,7 +491,12 @@ public function resolve($publicSuffix): self
485491
public function withPublicSuffix($publicSuffix): self
486492
{
487493
if (!$publicSuffix instanceof PublicSuffix) {
488-
$publicSuffix = new PublicSuffix($publicSuffix, '', ...$this->getIDNAOptions());
494+
$publicSuffix = new PublicSuffix(
495+
$publicSuffix,
496+
'',
497+
$this->getAsciiIDNAOption(),
498+
$this->getUnicodeIDNAOption()
499+
);
489500
}
490501

491502
$publicSuffix = $this->normalize($publicSuffix);
@@ -495,10 +506,15 @@ public function withPublicSuffix($publicSuffix): self
495506

496507
$domain = implode('.', array_reverse(array_slice($this->labels, count($this->publicSuffix))));
497508
if (null === $publicSuffix->getContent()) {
498-
return new self($domain, null, ...$this->getIDNAOptions());
509+
return new self($domain, null, $this->getAsciiIDNAOption(), $this->getUnicodeIDNAOption());
499510
}
500511

501-
return new self($domain.'.'.$publicSuffix->getContent(), $publicSuffix, ...$this->getIDNAOptions());
512+
return new self(
513+
$domain.'.'.$publicSuffix->getContent(),
514+
$publicSuffix,
515+
$this->getAsciiIDNAOption(),
516+
$this->getUnicodeIDNAOption()
517+
);
502518
}
503519

504520

@@ -526,13 +542,19 @@ public function withSubDomain($subDomain): self
526542
}
527543

528544
if (null === $subDomain) {
529-
return new self($this->registrableDomain, $this->publicSuffix, ...$this->getIDNAOptions());
545+
return new self(
546+
$this->registrableDomain,
547+
$this->publicSuffix,
548+
$this->getAsciiIDNAOption(),
549+
$this->getUnicodeIDNAOption()
550+
);
530551
}
531552

532553
return new self(
533554
$subDomain.'.'.$this->registrableDomain,
534555
$this->publicSuffix,
535-
...$this->getIDNAOptions()
556+
$this->getAsciiIDNAOption(),
557+
$this->getUnicodeIDNAOption()
536558
);
537559
}
538560

@@ -641,13 +663,19 @@ public function withLabel(int $key, $label): self
641663
ksort($labels);
642664

643665
if (null !== $this->publicSuffix->getLabel($key)) {
644-
return new self(implode('.', array_reverse($labels)), null, ...$this->getIDNAOptions());
666+
return new self(
667+
implode('.', array_reverse($labels)),
668+
null,
669+
$this->getAsciiIDNAOption(),
670+
$this->getUnicodeIDNAOption()
671+
);
645672
}
646673

647674
return new self(
648675
implode('.', array_reverse($labels)),
649676
$this->publicSuffix,
650-
...$this->getIDNAOptions()
677+
$this->getAsciiIDNAOption(),
678+
$this->getUnicodeIDNAOption()
651679
);
652680
}
653681

@@ -691,25 +719,18 @@ public function withoutLabel(int $key, int ...$keys): self
691719
}
692720

693721
if ([] === $labels) {
694-
return new self(null, null, ...$this->getIDNAOptions());
722+
return new self(null, null, $this->getAsciiIDNAOption(), $this->getUnicodeIDNAOption());
695723
}
696724

697725
$domain = implode('.', array_reverse($labels));
698726
$psContent = $this->publicSuffix->getContent();
699727
if (null === $psContent || '.'.$psContent !== substr($domain, - strlen($psContent) - 1)) {
700-
return new self($domain, null, ...$this->getIDNAOptions());
728+
return new self($domain, null, $this->getAsciiIDNAOption(), $this->getUnicodeIDNAOption());
701729
}
702730

703-
return new self($domain, $this->publicSuffix, ...$this->getIDNAOptions());
731+
return new self($domain, $this->publicSuffix, $this->getAsciiIDNAOption(), $this->getUnicodeIDNAOption());
704732
}
705733

706-
/**
707-
* @return array
708-
*/
709-
public function getIDNAOptions(): array
710-
{
711-
return [$this->asciiIDNAOption, $this->unicodeIDNAOption];
712-
}
713734

714735
public function getAsciiIDNAOption(): int
715736
{

src/PublicSuffix.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ public static function createFromDomain(Domain $domain): self
108108
$section = self::PRIVATE_DOMAINS;
109109
}
110110

111-
return new self($domain->getPublicSuffix(), $section, ...$domain->getIDNAOptions());
111+
return new self(
112+
$domain->getPublicSuffix(),
113+
$section,
114+
$domain->getAsciiIDNAOption(),
115+
$domain->getUnicodeIDNAOption()
116+
);
112117
}
113118

114119
/**
@@ -316,14 +321,15 @@ public function toUnicode()
316321
return $clone;
317322
}
318323

319-
/**
320-
* @return array
321-
*/
322-
public function getIDNAOptions(): array
324+
public function getAsciiIDNAOption(): int
323325
{
324-
return [$this->asciiIDNAOption, $this->unicodeIDNAOption];
326+
return $this->asciiIDNAOption;
325327
}
326328

329+
public function getUnicodeIDNAOption(): int
330+
{
331+
return $this->unicodeIDNAOption;
332+
}
327333
/**
328334
* return true if domain contains deviation characters.
329335
* @see http://unicode.org/reports/tr46/#Transition_Considerations

tests/DomainTest.php

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ public function testwithoutLabelWorksWithMultipleKeys()
991991
public function testConstructWithCustomIDNAOptions()
992992
{
993993
$domain = new Domain('example.com', null, IDNA_NONTRANSITIONAL_TO_ASCII, IDNA_NONTRANSITIONAL_TO_UNICODE);
994-
self::assertSame([16, 32], $domain->getIDNAOptions());
994+
self::assertSame([16, 32], [$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()]);
995995
}
996996

997997
/**
@@ -1086,23 +1086,50 @@ public function testInstanceCreationWithCustomIDNAOptions()
10861086
{
10871087
$domain = new Domain('example.com', new PublicSuffix('com'), 16, 32);
10881088
$instance = $domain->toAscii();
1089-
self::assertSame($domain->getIDNAOptions(), $instance->getIDNAOptions());
1089+
self::assertSame(
1090+
[$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()],
1091+
[$instance->getAsciiIDNAOption(), $instance->getUnicodeIDNAOption()]
1092+
);
10901093
$instance = $domain->toUnicode();
1091-
self::assertSame($domain->getIDNAOptions(), $instance->getIDNAOptions());
1094+
self::assertSame(
1095+
[$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()],
1096+
[$instance->getAsciiIDNAOption(), $instance->getUnicodeIDNAOption()]
1097+
);
10921098
$instance = $domain->withLabel(0, 'foo');
1093-
self::assertSame($domain->getIDNAOptions(), $instance->getIDNAOptions());
1099+
self::assertSame(
1100+
[$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()],
1101+
[$instance->getAsciiIDNAOption(), $instance->getUnicodeIDNAOption()]
1102+
);
10941103
$instance = $domain->withoutLabel(0);
1095-
self::assertSame($domain->getIDNAOptions(), $instance->getIDNAOptions());
1104+
self::assertSame(
1105+
[$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()],
1106+
[$instance->getAsciiIDNAOption(), $instance->getUnicodeIDNAOption()]
1107+
);
10961108
$instance = $domain->withPublicSuffix(new PublicSuffix('us'));
1097-
self::assertSame($domain->getIDNAOptions(), $instance->getIDNAOptions());
1109+
self::assertSame(
1110+
[$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()],
1111+
[$instance->getAsciiIDNAOption(), $instance->getUnicodeIDNAOption()]
1112+
);
10981113
$instance = $domain->withSubDomain('foo');
1099-
self::assertSame($domain->getIDNAOptions(), $instance->getIDNAOptions());
1114+
self::assertSame(
1115+
[$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()],
1116+
[$instance->getAsciiIDNAOption(), $instance->getUnicodeIDNAOption()]
1117+
);
11001118
$instance = $domain->append('bar');
1101-
self::assertSame($domain->getIDNAOptions(), $instance->getIDNAOptions());
1119+
self::assertSame(
1120+
[$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()],
1121+
[$instance->getAsciiIDNAOption(), $instance->getUnicodeIDNAOption()]
1122+
);
11021123
$instance = $domain->prepend('bar');
1103-
self::assertSame($domain->getIDNAOptions(), $instance->getIDNAOptions());
1124+
self::assertSame(
1125+
[$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()],
1126+
[$instance->getAsciiIDNAOption(), $instance->getUnicodeIDNAOption()]
1127+
);
11041128
$instance = $domain->resolve('com');
1105-
self::assertSame($domain->getIDNAOptions(), $instance->getIDNAOptions());
1129+
self::assertSame(
1130+
[$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()],
1131+
[$instance->getAsciiIDNAOption(), $instance->getUnicodeIDNAOption()]
1132+
);
11061133
}
11071134

11081135
/**

tests/PublicSuffixTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ public function testCreateFromDomainWorks(Domain $domain, $expected)
241241
self::assertSame($result->isKnown(), $domain->isKnown());
242242
self::assertSame($result->isICANN(), $domain->isICANN());
243243
self::assertSame($result->isPrivate(), $domain->isPrivate());
244-
self::assertSame($result->getIDNAOptions(), $domain->getIDNAOptions());
244+
self::assertSame(
245+
[$result->getAsciiIDNAOption(), $result->getUnicodeIDNAOption()],
246+
[$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()]
247+
);
245248
}
246249

247250
public function createFromDomainProvider()
@@ -287,7 +290,11 @@ public function testResolveWithCustomIDNAOptions(
287290
self::assertSame($expectedContent, $publicSuffix->getContent());
288291
self::assertSame($expectedAscii, $publicSuffix->toAscii()->getContent());
289292
self::assertSame($expectedUnicode, $publicSuffix->toUnicode()->getContent());
290-
self::assertSame($publicSuffix->getIDNAOptions(), $publicSuffix->toUnicode()->getIDNAOptions());
293+
$instance = $publicSuffix->toUnicode();
294+
self::assertSame(
295+
[$publicSuffix->getAsciiIDNAOption(), $publicSuffix->getUnicodeIDNAOption()],
296+
[$instance->getAsciiIDNAOption(), $instance->getUnicodeIDNAOption()]
297+
);
291298
self::assertSame($publicSuffix->isTransitionalDifferent(), $publicSuffix->toAscii()->isTransitionalDifferent());
292299
}
293300

tests/RulesTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,10 @@ public function testPublicSuffixSpec()
636636

637637
public function testResolveWithIDNAOptions()
638638
{
639+
$resolved = $this->rules->resolve('foo.de', Rules::ICANN_DOMAINS, 16, 32);
639640
self::assertSame(
640641
[16, 32],
641-
$this->rules->resolve('foo.de', Rules::ICANN_DOMAINS, 16, 32)->getIDNAOptions()
642+
[$resolved->getAsciiIDNAOption(), $resolved->getUnicodeIDNAOption()]
642643
);
643644
}
644645
}

tests/TopLevelDomainsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ public function testResolveWithUnregisteredTLD()
151151

152152
public function testResolveWithIDNAOptions()
153153
{
154-
self::assertSame([16, 32], $this->collection->resolve('foo.de', 16, 32)->getIDNAOptions());
154+
$resolved = $this->collection->resolve('foo.de', 16, 32);
155+
self::assertSame([16, 32], [$resolved->getAsciiIDNAOption(), $resolved->getUnicodeIDNAOption()]);
155156
}
156157
/**
157158
* @dataProvider validTldProvider

0 commit comments

Comments
 (0)