Skip to content

Commit c05d027

Browse files
committed
mass update changes
1 parent d44e380 commit c05d027

24 files changed

Lines changed: 298 additions & 67 deletions

phpunit.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
stopOnRisky="true"
1313
failOnRisky="true"
1414
failOnEmptyTestSuite="true"
15+
displayDetailsOnTestsThatTriggerWarnings="true"
1516
displayDetailsOnIncompleteTests="true"
1617
>
1718
<testsuites>
@@ -26,7 +27,8 @@
2627
</testsuite>
2728
</testsuites>
2829
<php>
30+
<ini name="display_errors" value="On" />
31+
<ini name="display_startup_errors" value="On" />
2932
<env name="APP_ENV" value="testing"/>
30-
<env name="DEFAULT_TIMEOUT" value="3.5"/>
3133
</php>
3234
</phpunit>

src/Abstracts/AbstractResourceRecordType.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ protected function parseMessage(): void
125125
'Response header length is invalid'
126126
);
127127
}
128-
129128
[
130129
'type' => $type,
131130
'class' => $class,
@@ -201,11 +200,11 @@ public function getHeader(): string
201200
}
202201

203202
/**
204-
* @return string
203+
* @inheritdoc
205204
*/
206-
public function getMessage(): string
205+
public function getMessage(): PacketMessageInterface
207206
{
208-
return $this->getHeader() . $this->getRData();
207+
return $this->message;
209208
}
210209

211210
/**
@@ -315,7 +314,7 @@ public function toArray(): array
315314
'host' => $this->getName(),
316315
'class' => $this->getClass()->getName(),
317316
'ttl' => $this->getTTL(),
318-
'type' => $this->getType(),
317+
'type' => $this->getType()->getName(),
319318
'value' => $this->getValue(),
320319
];
321320
}

src/Interfaces/Packet/PacketHeaderInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ public function withARCount(int $ar) : static;
304304
*/
305305
public function withANCount(int $an) : static;
306306

307+
/**
308+
* With NS count
309+
*
310+
* @param int $ns
311+
* @return $this
312+
*/
313+
public function withNSCount(int $ns) : static;
314+
307315
/**
308316
* With QD Count
309317
* @param int $qd

src/Interfaces/Packet/PacketResourceRecordsInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public function getRecords(): array;
4646
*/
4747
public function getFilteredType(string $type, bool $single = false) : null|array|ResourceRecordTypeInterface;
4848

49+
/**
50+
* Return array records
51+
* @uses ResourceRecordTypeInterface::toArray()
52+
* @return array<array>
53+
*/
54+
public function toArray() : array;
55+
4956
/**
5057
* @return Traversable<ResourceRecordTypeInterface>
5158
*/

src/Interfaces/ResourceRecord/ResourceRecordTypeInterface.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ public function getOffsetPosition() : int;
7474
public function getHeader() : string;
7575

7676
/**
77-
* Get message raw response answer data
77+
* Get message raw all response answer data
7878
*
79-
* @return string
79+
* @return PacketMessageInterface
8080
*/
81-
public function getMessage(): string;
81+
public function getMessage(): PacketMessageInterface;
8282

8383
/**
8484
* The dns name
@@ -141,7 +141,8 @@ public function getQueryMessage() : string;
141141
/**
142142
* Return array data
143143
*
144-
* @return array
144+
* @return array like dns_get_record()
145+
* @see \dns_get_record()
145146
*/
146147
public function toArray() : array;
147148
}

src/Packet/Header.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,17 @@ public function withANCount(int $an): static
340340
return $obj;
341341
}
342342

343+
/**
344+
* @inheritdoc
345+
*/
346+
public function withNSCount(int $ns): static
347+
{
348+
$obj = clone $this;
349+
$obj->nscount = $ns;
350+
$obj->message = null;
351+
return $obj;
352+
}
353+
343354
/**
344355
* @inheritdoc
345356
*/

src/Packet/Question.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ public function __serialize(): array
194194
* @param int $type
195195
* @param int $class
196196
* @return Question
197+
* @noinspection PhpDocMissingThrowsInspection
197198
*/
198199
public static function fromFilteredResponse(
199200
string $name,

src/Packet/Records.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use ArrayAccess\DnsRecord\Interfaces\ResourceRecord\ResourceRecordTypeInterface;
88
use ArrayIterator;
99
use Traversable;
10+
use function array_map;
11+
use function array_values;
1012
use function md5;
1113
use function serialize;
1214
use function strtoupper;
@@ -86,6 +88,14 @@ public function getFilteredType(string $type, bool $single = false) : null|array
8688
return $result === [] ? null : $result;
8789
}
8890

91+
/**
92+
* @inheritdoc
93+
*/
94+
public function toArray(): array
95+
{
96+
return array_map(static fn ($e) => $e->toArray(), array_values($this->getRecords()));
97+
}
98+
8999
/**
90100
* @inheritdoc
91101
*/

src/Resolver.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ public function createQueryOpcode(
152152
$class = trim($class?:IN::NAME)?:IN::NAME;
153153
$class = Lookup::resourceClass($class);
154154
$type = Lookup::resourceType($type);
155-
$isOpt = $type->getName() === OPT::TYPE;
155+
$typeName = $type->getName();
156+
$isOpt = $typeName === OPT::TYPE;
156157
if ($isOpt) { // if is OPT fallback to A
157158
$type = 'A';
158159
}
@@ -165,12 +166,13 @@ public function createQueryOpcode(
165166
}
166167
$dns = new DnsServerStorage(...$ss);
167168
}
169+
170+
$header = Header::createQueryHeader($opcode, null, $adFlag, $cdFlag, $recurse);
168171
$requestData = new RequestData(
169-
Header::createQueryHeader($opcode, null, $adFlag, $cdFlag, $recurse),
172+
$header,
170173
$dns,
171174
$question
172175
);
173-
174176
if ($isOpt || $dnsSec) {
175177
$requestData
176178
->getAdditionalRecords()

src/ResourceRecord/RRTypes/CERT.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use ArrayAccess\DnsRecord\Abstracts\AbstractResourceRecordType;
77
use function array_values;
8+
use function base64_encode;
89
use function substr;
910

1011
/**
@@ -56,26 +57,27 @@ protected function parseRData(string $message, int $rdataOffset): void
5657
//
5758
// copy the certificate
5859
//
59-
$this->certificate = substr($this->rData, 5, $this->rdLength - 5);
60+
$this->certificate = base64_encode(substr($this->rData, 5, $this->rdLength - 5));
6061
}
6162

62-
public function getFormat(): ?int
63+
public function getFormat(): int
6364
{
64-
return $this->format??null;
65+
return $this->format;
6566
}
6667

67-
public function getKeyTag(): ?int
68+
public function getKeyTag(): int
6869
{
69-
return $this->keyTag??null;
70+
return $this->keyTag;
7071
}
7172

72-
public function getAlgorithm(): ?string
73+
public function getAlgorithm(): string
7374
{
74-
return $this->algorithm??null;
75+
return $this->algorithm;
7576
}
7677

77-
public function getCertificate(): ?string
78+
public function getCertificate(): string
7879
{
79-
return $this->certificate??null;
80+
return $this->certificate;
8081
}
8182
}
83+
// @todo add toArray()

0 commit comments

Comments
 (0)