Skip to content

Commit 66ae4c3

Browse files
committed
Remove ResourceData#getTypeId()
1 parent 7d739c4 commit 66ae4c3

16 files changed

+6
-86
lines changed

src/Protocol/Encoding/Encoder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private function encodeResourceRecord(Context $ctx, ResourceRecord $record): boo
4343
$ctx->appendData(\pack('n2N', $record->getType(), $record->getClass(), $record->getTTL()));
4444

4545
$ctx->beginRecordData();
46-
$this->resourceDataEncoder->encode($ctx, $record->getData());
46+
$this->resourceDataEncoder->encode($ctx, $record->getType(), $record->getData());
4747

4848
if ($ctx->isDataLengthExceeded()) {
4949
$ctx->isTruncated = true;

src/Protocol/Encoding/ResourceDataEncoder.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ public function restoreDefaultEncoder(int $type)
6464
$this->encoders[$type] = self::DEFAULT_ENCODERS[$type] ?? null;
6565
}
6666

67-
public function encode(Context $ctx, ResourceData $data)
67+
public function encode(Context $ctx, int $typeId, ResourceData $data)
6868
{
69-
if (isset($this->encoders[$id = $data->getTypeId()])) {
70-
$this->encoders[$id]($ctx, $data);
69+
if (isset($this->encoders[$typeId])) {
70+
$this->encoders[$typeId]($ctx, $data);
7171
return;
7272
}
7373

7474
if (!$data instanceof RawResourceData) {
75-
throw new \UnexpectedValueException("Unknown resource data type: {{$id}}");
75+
throw new \UnexpectedValueException("Unknown resource data type: {{$typeId}}");
7676
}
7777

7878
$ctx->appendData($data->getData());

src/Records/ResourceData.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22

33
namespace DaveRandom\LibDNS\Records;
44

5-
interface ResourceData
6-
{
7-
function getTypeId(): int;
8-
}
5+
interface ResourceData { }

src/Records/ResourceData/A.php

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use DaveRandom\LibDNS\Protocol\DecodingContext;
66
use DaveRandom\LibDNS\Protocol\EncodingContext;
77
use DaveRandom\LibDNS\Records\ResourceData;
8-
use DaveRandom\LibDNS\Records\ResourceTypes;
98
use DaveRandom\Network\IPv4Address;
109

1110
final class A implements ResourceData
@@ -22,11 +21,6 @@ public function getAddress(): IPv4Address
2221
return $this->address;
2322
}
2423

25-
public function getTypeId(): int
26-
{
27-
return ResourceTypes::A;
28-
}
29-
3024
public static function decode(DecodingContext $ctx): A
3125
{
3226
return new A(\DaveRandom\LibDNS\decode_ipv4address($ctx));

src/Records/ResourceData/AAAA.php

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use DaveRandom\LibDNS\Protocol\DecodingContext;
66
use DaveRandom\LibDNS\Protocol\EncodingContext;
77
use DaveRandom\LibDNS\Records\ResourceData;
8-
use DaveRandom\LibDNS\Records\ResourceTypes;
98
use DaveRandom\Network\IPv6Address;
109

1110
final class AAAA implements ResourceData
@@ -22,11 +21,6 @@ public function getAddress(): IPv6Address
2221
return $this->address;
2322
}
2423

25-
public function getTypeId(): int
26-
{
27-
return ResourceTypes::AAAA;
28-
}
29-
3024
public static function decode(DecodingContext $ctx): AAAA
3125
{
3226
return new AAAA(\DaveRandom\LibDNS\decode_ipv6address($ctx));

src/Records/ResourceData/CNAME.php

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use DaveRandom\LibDNS\Protocol\DecodingContext;
66
use DaveRandom\LibDNS\Protocol\EncodingContext;
77
use DaveRandom\LibDNS\Records\ResourceData;
8-
use DaveRandom\LibDNS\Records\ResourceTypes;
98
use DaveRandom\Network\DomainName;
109

1110
final class CNAME implements ResourceData
@@ -22,11 +21,6 @@ public function getCanonicalName(): DomainName
2221
return $this->canonicalName;
2322
}
2423

25-
public function getTypeId(): int
26-
{
27-
return ResourceTypes::CNAME;
28-
}
29-
3024
public static function decode(DecodingContext $ctx): CNAME
3125
{
3226
return new CNAME(\DaveRandom\LibDNS\decode_domain_name($ctx));

src/Records/ResourceData/DNAME.php

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use DaveRandom\LibDNS\Protocol\DecodingContext;
66
use DaveRandom\LibDNS\Protocol\EncodingContext;
77
use DaveRandom\LibDNS\Records\ResourceData;
8-
use DaveRandom\LibDNS\Records\ResourceTypes;
98
use DaveRandom\Network\DomainName;
109

1110
final class DNAME implements ResourceData
@@ -22,11 +21,6 @@ public function getCanonicalName(): DomainName
2221
return $this->canonicalName;
2322
}
2423

25-
public function getTypeId(): int
26-
{
27-
return ResourceTypes::DNAME;
28-
}
29-
3024
public static function decode(DecodingContext $ctx): DNAME
3125
{
3226
return new DNAME(\DaveRandom\LibDNS\decode_domain_name($ctx));

src/Records/ResourceData/MX.php

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use DaveRandom\LibDNS\Protocol\DecodingContext;
66
use DaveRandom\LibDNS\Protocol\EncodingContext;
77
use DaveRandom\LibDNS\Records\ResourceData;
8-
use DaveRandom\LibDNS\Records\ResourceTypes;
98
use DaveRandom\Network\DomainName;
109

1110
final class MX implements ResourceData
@@ -29,11 +28,6 @@ public function getExchange(): DomainName
2928
return $this->exchange;
3029
}
3130

32-
public function getTypeId(): int
33-
{
34-
return ResourceTypes::MX;
35-
}
36-
3731
public static function decode(DecodingContext $ctx): MX
3832
{
3933
$preference = $ctx->unpack('n', 2)[1];

src/Records/ResourceData/NAPTR.php

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use DaveRandom\LibDNS\Protocol\DecodingContext;
66
use DaveRandom\LibDNS\Protocol\EncodingContext;
77
use DaveRandom\LibDNS\Records\ResourceData;
8-
use DaveRandom\LibDNS\Records\ResourceTypes;
98
use DaveRandom\Network\DomainName;
109

1110
final class NAPTR implements ResourceData
@@ -57,11 +56,6 @@ public function getReplacement(): DomainName
5756
return $this->replacement;
5857
}
5958

60-
public function getTypeId(): int
61-
{
62-
return ResourceTypes::NAPTR;
63-
}
64-
6559
public static function decode(DecodingContext $ctx): NAPTR
6660
{
6761
$parts = $ctx->unpack('norder/npreference', 4);

src/Records/ResourceData/NS.php

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use DaveRandom\LibDNS\Protocol\DecodingContext;
66
use DaveRandom\LibDNS\Protocol\EncodingContext;
77
use DaveRandom\LibDNS\Records\ResourceData;
8-
use DaveRandom\LibDNS\Records\ResourceTypes;
98
use DaveRandom\Network\DomainName;
109

1110
final class NS implements ResourceData
@@ -22,11 +21,6 @@ public function getAuthoritativeServerName(): DomainName
2221
return $this->authoritativeServerName;
2322
}
2423

25-
public function getTypeId(): int
26-
{
27-
return ResourceTypes::NS;
28-
}
29-
3024
public static function decode(DecodingContext $ctx): NS
3125
{
3226
return new NS(\DaveRandom\LibDNS\decode_domain_name($ctx));

src/Records/ResourceData/PTR.php

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use DaveRandom\LibDNS\Protocol\DecodingContext;
66
use DaveRandom\LibDNS\Protocol\EncodingContext;
77
use DaveRandom\LibDNS\Records\ResourceData;
8-
use DaveRandom\LibDNS\Records\ResourceTypes;
98
use DaveRandom\Network\DomainName;
109

1110
final class PTR implements ResourceData
@@ -22,11 +21,6 @@ public function getName(): DomainName
2221
return $this->name;
2322
}
2423

25-
public function getTypeId(): int
26-
{
27-
return ResourceTypes::PTR;
28-
}
29-
3024
public static function decode(DecodingContext $ctx): PTR
3125
{
3226
return new PTR(\DaveRandom\LibDNS\decode_domain_name($ctx));

src/Records/ResourceData/RP.php

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use DaveRandom\LibDNS\Protocol\DecodingContext;
66
use DaveRandom\LibDNS\Protocol\EncodingContext;
77
use DaveRandom\LibDNS\Records\ResourceData;
8-
use DaveRandom\LibDNS\Records\ResourceTypes;
98
use DaveRandom\Network\DomainName;
109

1110
final class RP implements ResourceData
@@ -29,11 +28,6 @@ public function getTxtName(): DomainName
2928
return $this->txtName;
3029
}
3130

32-
public function getTypeId(): int
33-
{
34-
return ResourceTypes::RP;
35-
}
36-
3731
public static function decode(DecodingContext $ctx): RP
3832
{
3933
$mailboxName = \DaveRandom\LibDNS\decode_domain_name($ctx);

src/Records/ResourceData/SOA.php

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use DaveRandom\LibDNS\Protocol\DecodingContext;
66
use DaveRandom\LibDNS\Protocol\EncodingContext;
77
use DaveRandom\LibDNS\Records\ResourceData;
8-
use DaveRandom\LibDNS\Records\ResourceTypes;
98
use DaveRandom\Network\DomainName;
109

1110
final class SOA implements ResourceData
@@ -91,11 +90,6 @@ public function getTtl(): int
9190
return $this->ttl;
9291
}
9392

94-
public function getTypeId(): int
95-
{
96-
return ResourceTypes::SOA;
97-
}
98-
9993
public static function decode(DecodingContext $ctx): SOA
10094
{
10195
$masterServerName = \DaveRandom\LibDNS\decode_domain_name($ctx);

src/Records/ResourceData/SRV.php

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use DaveRandom\LibDNS\Protocol\DecodingContext;
66
use DaveRandom\LibDNS\Protocol\EncodingContext;
77
use DaveRandom\LibDNS\Records\ResourceData;
8-
use DaveRandom\LibDNS\Records\ResourceTypes;
98
use DaveRandom\Network\DomainName;
109

1110
final class SRV implements ResourceData
@@ -43,11 +42,6 @@ public function getTarget(): DomainName
4342
return $this->target;
4443
}
4544

46-
public function getTypeId(): int
47-
{
48-
return ResourceTypes::SRV;
49-
}
50-
5145
public static function decode(DecodingContext $ctx): SRV
5246
{
5347
$parts = $ctx->unpack('npriority/nweight/nport', 6);

src/Records/ResourceData/TXT.php

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use DaveRandom\LibDNS\Protocol\DecodingContext;
66
use DaveRandom\LibDNS\Protocol\EncodingContext;
77
use DaveRandom\LibDNS\Records\ResourceData;
8-
use DaveRandom\LibDNS\Records\ResourceTypes;
98

109
final class TXT implements ResourceData
1110
{
@@ -27,11 +26,6 @@ public function getStrings(): array
2726
return $this->strings;
2827
}
2928

30-
public function getTypeId(): int
31-
{
32-
return ResourceTypes::TXT;
33-
}
34-
3529
public static function decode(DecodingContext $ctx, int $length): TXT
3630
{
3731
$consumed = 0;

src/Records/ResourceData/UnknownResourceData.php

-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ public function __construct(int $typeId, string $data)
1515
$this->data = $data;
1616
}
1717

18-
public function getTypeId(): int
19-
{
20-
return $this->typeId;
21-
}
22-
2318
public function getData(): string
2419
{
2520
return $this->data;

0 commit comments

Comments
 (0)