@@ -108,20 +108,20 @@ private function parseQuestion($data, $consumed)
108
108
list ($ labels , $ consumed ) = $ this ->readLabels ($ data , $ consumed );
109
109
110
110
if ($ labels === null || !isset ($ data [$ consumed + 4 - 1 ])) {
111
- return array ( null , null ) ;
111
+ return [ null , null ] ;
112
112
}
113
113
114
114
list ($ type , $ class ) = array_values (unpack ('n* ' , substr ($ data , $ consumed , 4 )));
115
115
$ consumed += 4 ;
116
116
117
- return array (
117
+ return [
118
118
new Query (
119
119
implode ('. ' , $ labels ),
120
120
$ type ,
121
121
$ class
122
122
),
123
123
$ consumed
124
- ) ;
124
+ ] ;
125
125
}
126
126
127
127
/**
@@ -134,7 +134,7 @@ private function parseRecord($data, $consumed)
134
134
list ($ name , $ consumed ) = $ this ->readDomain ($ data , $ consumed );
135
135
136
136
if ($ name === null || !isset ($ data [$ consumed + 10 - 1 ])) {
137
- return array ( null , null ) ;
137
+ return [ null , null ] ;
138
138
}
139
139
140
140
list ($ type , $ class ) = array_values (unpack ('n* ' , substr ($ data , $ consumed , 4 )));
@@ -152,7 +152,7 @@ private function parseRecord($data, $consumed)
152
152
$ consumed += 2 ;
153
153
154
154
if (!isset ($ data [$ consumed + $ rdLength - 1 ])) {
155
- return array ( null , null ) ;
155
+ return [ null , null ] ;
156
156
}
157
157
158
158
$ rdata = null ;
@@ -171,7 +171,7 @@ private function parseRecord($data, $consumed)
171
171
} elseif (Message::TYPE_CNAME === $ type || Message::TYPE_PTR === $ type || Message::TYPE_NS === $ type ) {
172
172
list ($ rdata , $ consumed ) = $ this ->readDomain ($ data , $ consumed );
173
173
} elseif (Message::TYPE_TXT === $ type || Message::TYPE_SPF === $ type ) {
174
- $ rdata = array () ;
174
+ $ rdata = [] ;
175
175
while ($ consumed < $ expected ) {
176
176
$ len = ord ($ data [$ consumed ]);
177
177
$ rdata [] = (string )substr ($ data , $ consumed + 1 , $ len );
@@ -182,34 +182,34 @@ private function parseRecord($data, $consumed)
182
182
list ($ priority ) = array_values (unpack ('n ' , substr ($ data , $ consumed , 2 )));
183
183
list ($ target , $ consumed ) = $ this ->readDomain ($ data , $ consumed + 2 );
184
184
185
- $ rdata = array (
185
+ $ rdata = [
186
186
'priority ' => $ priority ,
187
187
'target ' => $ target
188
- ) ;
188
+ ] ;
189
189
}
190
190
} elseif (Message::TYPE_SRV === $ type ) {
191
191
if ($ rdLength > 6 ) {
192
192
list ($ priority , $ weight , $ port ) = array_values (unpack ('n* ' , substr ($ data , $ consumed , 6 )));
193
193
list ($ target , $ consumed ) = $ this ->readDomain ($ data , $ consumed + 6 );
194
194
195
- $ rdata = array (
195
+ $ rdata = [
196
196
'priority ' => $ priority ,
197
197
'weight ' => $ weight ,
198
198
'port ' => $ port ,
199
199
'target ' => $ target
200
- ) ;
200
+ ] ;
201
201
}
202
202
} elseif (Message::TYPE_SSHFP === $ type ) {
203
203
if ($ rdLength > 2 ) {
204
204
list ($ algorithm , $ hash ) = \array_values (\unpack ('C* ' , \substr ($ data , $ consumed , 2 )));
205
205
$ fingerprint = \bin2hex (\substr ($ data , $ consumed + 2 , $ rdLength - 2 ));
206
206
$ consumed += $ rdLength ;
207
207
208
- $ rdata = array (
208
+ $ rdata = [
209
209
'algorithm ' => $ algorithm ,
210
210
'type ' => $ hash ,
211
211
'fingerprint ' => $ fingerprint
212
- ) ;
212
+ ] ;
213
213
}
214
214
} elseif (Message::TYPE_SOA === $ type ) {
215
215
list ($ mname , $ consumed ) = $ this ->readDomain ($ data , $ consumed );
@@ -219,18 +219,18 @@ private function parseRecord($data, $consumed)
219
219
list ($ serial , $ refresh , $ retry , $ expire , $ minimum ) = array_values (unpack ('N* ' , substr ($ data , $ consumed , 20 )));
220
220
$ consumed += 20 ;
221
221
222
- $ rdata = array (
222
+ $ rdata = [
223
223
'mname ' => $ mname ,
224
224
'rname ' => $ rname ,
225
225
'serial ' => $ serial ,
226
226
'refresh ' => $ refresh ,
227
227
'retry ' => $ retry ,
228
228
'expire ' => $ expire ,
229
229
'minimum ' => $ minimum
230
- ) ;
230
+ ] ;
231
231
}
232
232
} elseif (Message::TYPE_OPT === $ type ) {
233
- $ rdata = array () ;
233
+ $ rdata = [] ;
234
234
while (isset ($ data [$ consumed + 4 - 1 ])) {
235
235
list ($ code , $ length ) = array_values (unpack ('n* ' , substr ($ data , $ consumed , 4 )));
236
236
$ value = (string ) substr ($ data , $ consumed + 4 , $ length );
@@ -254,11 +254,11 @@ private function parseRecord($data, $consumed)
254
254
$ value = substr ($ data , $ consumed + 2 + $ tagLength , $ rdLength - 2 - $ tagLength );
255
255
$ consumed += $ rdLength ;
256
256
257
- $ rdata = array (
257
+ $ rdata = [
258
258
'flag ' => $ flag ,
259
259
'tag ' => $ tag ,
260
260
'value ' => $ value
261
- ) ;
261
+ ] ;
262
262
}
263
263
}
264
264
} else {
@@ -269,25 +269,25 @@ private function parseRecord($data, $consumed)
269
269
270
270
// ensure parsing record data consumes expact number of bytes indicated in record length
271
271
if ($ consumed !== $ expected || $ rdata === null ) {
272
- return array ( null , null ) ;
272
+ return [ null , null ] ;
273
273
}
274
274
275
- return array (
275
+ return [
276
276
new Record ($ name , $ type , $ class , $ ttl , $ rdata ),
277
277
$ consumed
278
- ) ;
278
+ ] ;
279
279
}
280
280
281
281
private function readDomain ($ data , $ consumed )
282
282
{
283
283
list ($ labels , $ consumed ) = $ this ->readLabels ($ data , $ consumed );
284
284
285
285
if ($ labels === null ) {
286
- return array ( null , null ) ;
286
+ return [ null , null ] ;
287
287
}
288
288
289
289
// use escaped notation for each label part, then join using dots
290
- return array (
290
+ return [
291
291
\implode (
292
292
'. ' ,
293
293
\array_map (
@@ -298,7 +298,7 @@ function ($label) {
298
298
)
299
299
),
300
300
$ consumed
301
- ) ;
301
+ ] ;
302
302
}
303
303
304
304
/**
@@ -309,11 +309,11 @@ function ($label) {
309
309
*/
310
310
private function readLabels ($ data , $ consumed , $ compressionDepth = 127 )
311
311
{
312
- $ labels = array () ;
312
+ $ labels = [] ;
313
313
314
314
while (true ) {
315
315
if (!isset ($ data [$ consumed ])) {
316
- return array ( null , null ) ;
316
+ return [ null , null ] ;
317
317
}
318
318
319
319
$ length = \ord ($ data [$ consumed ]);
@@ -328,14 +328,14 @@ private function readLabels($data, $consumed, $compressionDepth = 127)
328
328
if (($ length & 0xc0 ) === 0xc0 && isset ($ data [$ consumed + 1 ]) && $ compressionDepth ) {
329
329
$ offset = ($ length & ~0xc0 ) << 8 | \ord ($ data [$ consumed + 1 ]);
330
330
if ($ offset >= $ consumed ) {
331
- return array ( null , null ) ;
331
+ return [ null , null ] ;
332
332
}
333
333
334
334
$ consumed += 2 ;
335
335
list ($ newLabels ) = $ this ->readLabels ($ data , $ offset , $ compressionDepth - 1 );
336
336
337
337
if ($ newLabels === null ) {
338
- return array ( null , null ) ;
338
+ return [ null , null ] ;
339
339
}
340
340
341
341
$ labels = array_merge ($ labels , $ newLabels );
@@ -344,13 +344,13 @@ private function readLabels($data, $consumed, $compressionDepth = 127)
344
344
345
345
// length MUST be 0-63 (6 bits only) and data has to be large enough
346
346
if ($ length & 0xc0 || !isset ($ data [$ consumed + $ length - 1 ])) {
347
- return array ( null , null ) ;
347
+ return [ null , null ] ;
348
348
}
349
349
350
350
$ labels [] = substr ($ data , $ consumed + 1 , $ length );
351
351
$ consumed += $ length + 1 ;
352
352
}
353
353
354
- return array ( $ labels , $ consumed) ;
354
+ return [ $ labels , $ consumed] ;
355
355
}
356
356
}
0 commit comments