@@ -44,7 +44,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
44
44
* @param string $rootNodeName
45
45
* @param int|null $loadOptions A bit field of LIBXML_* constants
46
46
*/
47
- public function __construct ($ rootNodeName = 'response ' , $ loadOptions = null )
47
+ public function __construct (string $ rootNodeName = 'response ' , int $ loadOptions = null )
48
48
{
49
49
$ this ->rootNodeName = $ rootNodeName ;
50
50
$ this ->loadOptions = null !== $ loadOptions ? $ loadOptions : LIBXML_NONET | LIBXML_NOBLANKS ;
@@ -180,15 +180,9 @@ public function getRootNodeName()
180
180
return $ this ->rootNodeName ;
181
181
}
182
182
183
- /**
184
- * @param \DOMNode $node
185
- * @param string $val
186
- *
187
- * @return bool
188
- */
189
- final protected function appendXMLString (\DOMNode $ node , $ val )
183
+ final protected function appendXMLString (\DOMNode $ node , string $ val ): bool
190
184
{
191
- if (strlen ( $ val ) > 0 ) {
185
+ if ('' !== $ val ) {
192
186
$ frag = $ this ->dom ->createDocumentFragment ();
193
187
$ frag ->appendXML ($ val );
194
188
$ node ->appendChild ($ frag );
@@ -199,27 +193,15 @@ final protected function appendXMLString(\DOMNode $node, $val)
199
193
return false ;
200
194
}
201
195
202
- /**
203
- * @param \DOMNode $node
204
- * @param string $val
205
- *
206
- * @return bool
207
- */
208
- final protected function appendText (\DOMNode $ node , $ val )
196
+ final protected function appendText (\DOMNode $ node , string $ val ): bool
209
197
{
210
198
$ nodeText = $ this ->dom ->createTextNode ($ val );
211
199
$ node ->appendChild ($ nodeText );
212
200
213
201
return true ;
214
202
}
215
203
216
- /**
217
- * @param \DOMNode $node
218
- * @param string $val
219
- *
220
- * @return bool
221
- */
222
- final protected function appendCData (\DOMNode $ node , $ val )
204
+ final protected function appendCData (\DOMNode $ node , string $ val ): bool
223
205
{
224
206
$ nodeText = $ this ->dom ->createCDATASection ($ val );
225
207
$ node ->appendChild ($ nodeText );
@@ -230,10 +212,8 @@ final protected function appendCData(\DOMNode $node, $val)
230
212
/**
231
213
* @param \DOMNode $node
232
214
* @param \DOMDocumentFragment $fragment
233
- *
234
- * @return bool
235
215
*/
236
- final protected function appendDocumentFragment (\DOMNode $ node , $ fragment )
216
+ final protected function appendDocumentFragment (\DOMNode $ node , $ fragment ): bool
237
217
{
238
218
if ($ fragment instanceof \DOMDocumentFragment) {
239
219
$ node ->appendChild ($ fragment );
@@ -246,12 +226,8 @@ final protected function appendDocumentFragment(\DOMNode $node, $fragment)
246
226
247
227
/**
248
228
* Checks the name is a valid xml element name.
249
- *
250
- * @param string $name
251
- *
252
- * @return bool
253
229
*/
254
- final protected function isElementNameValid ($ name )
230
+ final protected function isElementNameValid (string $ name ): bool
255
231
{
256
232
return $ name &&
257
233
false === strpos ($ name , ' ' ) &&
@@ -294,10 +270,8 @@ private function parseXml(\DOMNode $node, array $context = array())
294
270
295
271
/**
296
272
* Parse the input DOMNode attributes into an array.
297
- *
298
- * @return array
299
273
*/
300
- private function parseXmlAttributes (\DOMNode $ node , array $ context = array ())
274
+ private function parseXmlAttributes (\DOMNode $ node , array $ context = array ()): array
301
275
{
302
276
if (!$ node ->hasAttributes ()) {
303
277
return array ();
@@ -374,13 +348,10 @@ private function parseXmlValue(\DOMNode $node, array $context = array())
374
348
*
375
349
* @param \DOMNode $parentNode
376
350
* @param array|object $data
377
- * @param string|null $xmlRootNodeName
378
- *
379
- * @return bool
380
351
*
381
352
* @throws NotEncodableValueException
382
353
*/
383
- private function buildXml (\DOMNode $ parentNode , $ data , $ xmlRootNodeName = null )
354
+ private function buildXml (\DOMNode $ parentNode , $ data , string $ xmlRootNodeName = null ): bool
384
355
{
385
356
$ append = true ;
386
357
@@ -443,12 +414,8 @@ private function buildXml(\DOMNode $parentNode, $data, $xmlRootNodeName = null)
443
414
*
444
415
* @param \DOMNode $parentNode
445
416
* @param array|object $data
446
- * @param string $nodeName
447
- * @param string $key
448
- *
449
- * @return bool
450
417
*/
451
- private function appendNode (\DOMNode $ parentNode , $ data , $ nodeName , $ key = null )
418
+ private function appendNode (\DOMNode $ parentNode , $ data , string $ nodeName , string $ key = null ): bool
452
419
{
453
420
$ node = $ this ->dom ->createElement ($ nodeName );
454
421
if (null !== $ key ) {
@@ -465,12 +432,8 @@ private function appendNode(\DOMNode $parentNode, $data, $nodeName, $key = null)
465
432
466
433
/**
467
434
* Checks if a value contains any characters which would require CDATA wrapping.
468
- *
469
- * @param string $val
470
- *
471
- * @return bool
472
435
*/
473
- private function needsCdataWrapping ($ val )
436
+ private function needsCdataWrapping (string $ val ): bool
474
437
{
475
438
return 0 < preg_match ('/[<>&]/ ' , $ val );
476
439
}
@@ -481,11 +444,9 @@ private function needsCdataWrapping($val)
481
444
* @param \DOMNode $node
482
445
* @param mixed $val
483
446
*
484
- * @return bool
485
- *
486
447
* @throws NotEncodableValueException
487
448
*/
488
- private function selectNodeType (\DOMNode $ node , $ val )
449
+ private function selectNodeType (\DOMNode $ node , $ val ): bool
489
450
{
490
451
if (is_array ($ val )) {
491
452
return $ this ->buildXml ($ node , $ val );
@@ -514,10 +475,8 @@ private function selectNodeType(\DOMNode $node, $val)
514
475
515
476
/**
516
477
* Get real XML root node name, taking serializer options into account.
517
- *
518
- * @return string
519
478
*/
520
- private function resolveXmlRootName (array $ context = array ())
479
+ private function resolveXmlRootName (array $ context = array ()): string
521
480
{
522
481
return isset ($ context ['xml_root_node_name ' ])
523
482
? $ context ['xml_root_node_name ' ]
@@ -526,12 +485,8 @@ private function resolveXmlRootName(array $context = array())
526
485
527
486
/**
528
487
* Get XML option for type casting attributes Defaults to true.
529
- *
530
- * @param array $context
531
- *
532
- * @return bool
533
488
*/
534
- private function resolveXmlTypeCastAttributes (array $ context = array ())
489
+ private function resolveXmlTypeCastAttributes (array $ context = array ()): bool
535
490
{
536
491
return isset ($ context ['xml_type_cast_attributes ' ])
537
492
? (bool ) $ context ['xml_type_cast_attributes ' ]
@@ -540,12 +495,8 @@ private function resolveXmlTypeCastAttributes(array $context = array())
540
495
541
496
/**
542
497
* Create a DOM document, taking serializer options into account.
543
- *
544
- * @param array $context Options that the encoder has access to
545
- *
546
- * @return \DOMDocument
547
498
*/
548
- private function createDomDocument (array $ context )
499
+ private function createDomDocument (array $ context ): \ DOMDocument
549
500
{
550
501
$ document = new \DOMDocument ();
551
502
0 commit comments