From c045b663f34a4e4aa9d4d623bd836b23cb3b998d Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Mon, 12 Dec 2022 09:40:40 -0400 Subject: [PATCH] Revert v2 to 2.16.0 (#200) This will provide a clean slate to continue v2 support. --- src/ArrayToXml.php | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/ArrayToXml.php b/src/ArrayToXml.php index 33fd37b..66eb49e 100644 --- a/src/ArrayToXml.php +++ b/src/ArrayToXml.php @@ -17,9 +17,6 @@ class ArrayToXml protected $numericTagNamePrefix = 'numeric_'; - /** - * @param mixed[] $array - */ public function __construct( array $array, $rootElement = '', @@ -52,14 +49,11 @@ public function __construct( $this->convertElement($root, $array); } - public function setNumericTagNamePrefix(string $prefix): void + public function setNumericTagNamePrefix(string $prefix) { $this->numericTagNamePrefix = $prefix; } - /** - * @param mixed[] $array - */ public static function convert( array $array, $rootElement = '', @@ -68,7 +62,7 @@ public static function convert( string $xmlVersion = '1.0', array $domProperties = [], bool $xmlStandalone = null - ): string { + ) { $converter = new static( $array, $rootElement, @@ -96,7 +90,7 @@ public function toDom(): DOMDocument return $this->document; } - protected function ensureValidDomProperties(array $domProperties): void + protected function ensureValidDomProperties(array $domProperties) { foreach ($domProperties as $key => $value) { if (! property_exists($this->document, $key)) { @@ -105,7 +99,7 @@ protected function ensureValidDomProperties(array $domProperties): void } } - public function setDomProperties(array $domProperties): self + public function setDomProperties(array $domProperties) { $this->ensureValidDomProperties($domProperties); @@ -116,7 +110,7 @@ public function setDomProperties(array $domProperties): self return $this; } - public function prettify(): self + public function prettify() { $this->document->preserveWhiteSpace = false; $this->document->formatOutput = true; @@ -124,17 +118,14 @@ public function prettify(): self return $this; } - public function dropXmlDeclaration(): self + public function dropXmlDeclaration() { $this->addXmlDeclaration = false; return $this; } - /** - * @param mixed[]|mixed $value - */ - private function convertElement(DOMElement $element, $value): void + private function convertElement(DOMElement $element, $value) { $sequential = $this->isArrayAllKeySequential($value); @@ -175,14 +166,14 @@ private function convertElement(DOMElement $element, $value): void } } - protected function addNumericNode(DOMElement $element, $value): void + protected function addNumericNode(DOMElement $element, $value) { foreach ($value as $key => $item) { $this->convertElement($element, [$this->numericTagNamePrefix.$key => $item]); } } - protected function addNode(DOMElement $element, $key, $value): void + protected function addNode(DOMElement $element, $key, $value) { if ($this->replaceSpacesByUnderScoresInKeyNames) { $key = str_replace(' ', '_', $key); @@ -193,7 +184,7 @@ protected function addNode(DOMElement $element, $key, $value): void $this->convertElement($child, $value); } - protected function addCollectionNode(DOMElement $element, $value): void + protected function addCollectionNode(DOMElement $element, $value) { if ($element->childNodes->length === 0 && $element->attributes->length === 0) { $this->convertElement($element, $value); @@ -219,10 +210,6 @@ protected function addSequentialNode(DOMElement $element, $value) $element->parentNode->appendChild($child); } - /** - * @param mixed[] $value - * @return bool|mixed[] - */ protected function isArrayAllKeySequential($value) { if (! is_array($value)) { @@ -240,7 +227,7 @@ protected function isArrayAllKeySequential($value) return array_unique(array_map('is_int', array_keys($value))) === [true]; } - protected function addAttributes(DOMElement $element, array $data): void + protected function addAttributes(DOMElement $element, array $data) { foreach ($data as $attrKey => $attrVal) { $element->setAttribute($attrKey, $attrVal);