From e46df26c36545838a326a56bdc134a5e6457198b Mon Sep 17 00:00:00 2001
From: freek
Date: Fri, 23 Apr 2021 13:54:18 +0200
Subject: [PATCH] nipicks
---
src/ArrayToXml.php | 20 ++++--------
tests/ArrayToXmlTest.php | 7 ++---
..._be_set_in_simplexml_element_style__1.txt} | 0
...so_be_set_in_simplexmlelement_style__1.php | 5 ---
..._be_set_in_simplexml_element_style__1.txt} | 0
...so_be_set_in_simplexmlelement_style__1.php | 5 ---
..._it_accepts_an_xml_standalone_value__1.php | 5 ---
...oXmlTest__it_accepts_an_xml_version__1.php | 5 ---
...mlTest__it_can_drop_xml_declaration__1.php | 3 --
...oXmlTest__it_can_handle_custom_keys__1.php | 5 ---
...tom_keys_containing_colon_character__1.php | 5 ---
...XmlTest__it_can_handle_numeric_keys__1.php | 5 ---
...XmlTest__it_can_handle_numeric_keys__1.xml | 31 -------------------
...Test__it_can_handle_numeric_keys__1__1.php | 5 ---
...__it_can_handle_values_set_as_cdata__1.php | 5 ---
...__it_can_handle_values_set_as_mixed__1.php | 5 ---
..._in_collection_and_sequential_nodes__1.php | 5 ---
17 files changed, 9 insertions(+), 107 deletions(-)
rename tests/__snapshots__/{ArrayToXmlTest__and_cdata_values_can_also_be_set_in_simplexmlelement_style__1.txt => ArrayToXmlTest__and_cdata_values_can_also_be_set_in_simplexml_element_style__1.txt} (100%)
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__and_cdata_values_can_also_be_set_in_simplexmlelement_style__1.php
rename tests/__snapshots__/{ArrayToXmlTest__and_mixed_values_can_also_be_set_in_simplexmlelement_style__1.txt => ArrayToXmlTest__and_mixed_values_can_also_be_set_in_simplexml_element_style__1.txt} (100%)
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__and_mixed_values_can_also_be_set_in_simplexmlelement_style__1.php
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__it_accepts_an_xml_standalone_value__1.php
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__it_accepts_an_xml_version__1.php
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__it_can_drop_xml_declaration__1.php
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__it_can_handle_custom_keys__1.php
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__it_can_handle_custom_keys_containing_colon_character__1.php
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__it_can_handle_numeric_keys__1.php
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__it_can_handle_numeric_keys__1.xml
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__it_can_handle_numeric_keys__1__1.php
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__it_can_handle_values_set_as_cdata__1.php
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__it_can_handle_values_set_as_mixed__1.php
delete mode 100644 tests/__snapshots__/ArrayToXmlTest__it_doesnt_pollute_attributes_in_collection_and_sequential_nodes__1.php
diff --git a/src/ArrayToXml.php b/src/ArrayToXml.php
index d04db39..b8caeba 100644
--- a/src/ArrayToXml.php
+++ b/src/ArrayToXml.php
@@ -78,11 +78,9 @@ public static function convert(
public function toXml(): string
{
- if ($this->addXmlDeclaration === false) {
- return $this->document->saveXml($this->document->documentElement);
- }
-
- return $this->document->saveXML();
+ return $this->addXmlDeclaration
+ ? $this->document->saveXML()
+ : $this->document->saveXml($this->document->documentElement);
}
public function toDom(): DOMDocument
@@ -94,7 +92,7 @@ protected function ensureValidDomProperties(array $domProperties): void
{
foreach ($domProperties as $key => $value) {
if (! property_exists($this->document, $key)) {
- throw new Exception($key.' is not a valid property of DOMDocument');
+ throw new Exception("{$key} is not a valid property of DOMDocument");
}
}
}
@@ -125,10 +123,7 @@ public function dropXmlDeclaration(): self
return $this;
}
- /**
- * @param mixed[]|mixed $value
- */
- private function convertElement(DOMElement $element, $value): void
+ protected function convertElement(DOMElement $element, mixed $value): void
{
$sequential = $this->isArrayAllKeySequential($value);
@@ -213,10 +208,7 @@ protected function addSequentialNode(DOMElement $element, $value): void
$element->parentNode->appendChild($child);
}
- /**
- * @return bool|mixed[]
- */
- protected function isArrayAllKeySequential(array | string $value): mixed
+ protected function isArrayAllKeySequential(array | string $value): bool
{
if (! is_array($value)) {
return false;
diff --git a/tests/ArrayToXmlTest.php b/tests/ArrayToXmlTest.php
index 59edb50..bc0ef95 100644
--- a/tests/ArrayToXmlTest.php
+++ b/tests/ArrayToXmlTest.php
@@ -8,8 +8,7 @@ class ArrayToXmlTest extends TestCase
{
use MatchesSnapshots;
- /** @test array */
- protected $testArray = [];
+ protected array $testArray = [];
public function setUp(): void
{
@@ -274,7 +273,7 @@ public function it_can_handle_values_set_as_cdata()
}
/** @test */
- public function and_cdata_values_can_also_be_set_in_simplexmlelement_style()
+ public function and_cdata_values_can_also_be_set_in_simplexml_element_style()
{
$this->assertMatchesSnapshot(ArrayToXml::convert([
'movie' => [
@@ -341,7 +340,7 @@ public function it_can_handle_values_set_as_mixed()
}
/** @test */
- public function and_mixed_values_can_also_be_set_in_simplexmlelement_style()
+ public function and_mixed_values_can_also_be_set_in_simplexml_element_style()
{
$this->assertMatchesSnapshot(ArrayToXml::convert([
'movie' => [
diff --git a/tests/__snapshots__/ArrayToXmlTest__and_cdata_values_can_also_be_set_in_simplexmlelement_style__1.txt b/tests/__snapshots__/ArrayToXmlTest__and_cdata_values_can_also_be_set_in_simplexml_element_style__1.txt
similarity index 100%
rename from tests/__snapshots__/ArrayToXmlTest__and_cdata_values_can_also_be_set_in_simplexmlelement_style__1.txt
rename to tests/__snapshots__/ArrayToXmlTest__and_cdata_values_can_also_be_set_in_simplexml_element_style__1.txt
diff --git a/tests/__snapshots__/ArrayToXmlTest__and_cdata_values_can_also_be_set_in_simplexmlelement_style__1.php b/tests/__snapshots__/ArrayToXmlTest__and_cdata_values_can_also_be_set_in_simplexmlelement_style__1.php
deleted file mode 100644
index 404ef01..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__and_cdata_values_can_also_be_set_in_simplexmlelement_style__1.php
+++ /dev/null
@@ -1,5 +0,0 @@
-
-STAR WARS
]]>tom & jerry]]>
-';
diff --git a/tests/__snapshots__/ArrayToXmlTest__and_mixed_values_can_also_be_set_in_simplexmlelement_style__1.txt b/tests/__snapshots__/ArrayToXmlTest__and_mixed_values_can_also_be_set_in_simplexml_element_style__1.txt
similarity index 100%
rename from tests/__snapshots__/ArrayToXmlTest__and_mixed_values_can_also_be_set_in_simplexmlelement_style__1.txt
rename to tests/__snapshots__/ArrayToXmlTest__and_mixed_values_can_also_be_set_in_simplexml_element_style__1.txt
diff --git a/tests/__snapshots__/ArrayToXmlTest__and_mixed_values_can_also_be_set_in_simplexmlelement_style__1.php b/tests/__snapshots__/ArrayToXmlTest__and_mixed_values_can_also_be_set_in_simplexmlelement_style__1.php
deleted file mode 100644
index 1e746ec..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__and_mixed_values_can_also_be_set_in_simplexmlelement_style__1.php
+++ /dev/null
@@ -1,5 +0,0 @@
-
-STAR WARS Figure 1ROBOCOP Figure 2
-';
diff --git a/tests/__snapshots__/ArrayToXmlTest__it_accepts_an_xml_standalone_value__1.php b/tests/__snapshots__/ArrayToXmlTest__it_accepts_an_xml_standalone_value__1.php
deleted file mode 100644
index 89a1f24..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__it_accepts_an_xml_standalone_value__1.php
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-';
diff --git a/tests/__snapshots__/ArrayToXmlTest__it_accepts_an_xml_version__1.php b/tests/__snapshots__/ArrayToXmlTest__it_accepts_an_xml_version__1.php
deleted file mode 100644
index 106de26..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__it_accepts_an_xml_version__1.php
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-';
diff --git a/tests/__snapshots__/ArrayToXmlTest__it_can_drop_xml_declaration__1.php b/tests/__snapshots__/ArrayToXmlTest__it_can_drop_xml_declaration__1.php
deleted file mode 100644
index e04e9a0..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__it_can_drop_xml_declaration__1.php
+++ /dev/null
@@ -1,3 +0,0 @@
-soap:value';
diff --git a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_custom_keys__1.php b/tests/__snapshots__/ArrayToXmlTest__it_can_handle_custom_keys__1.php
deleted file mode 100644
index e1c066a..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_custom_keys__1.php
+++ /dev/null
@@ -1,5 +0,0 @@
-
-aaa3abc3bb3abb3abc3acb3
-';
diff --git a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_custom_keys_containing_colon_character__1.php b/tests/__snapshots__/ArrayToXmlTest__it_can_handle_custom_keys_containing_colon_character__1.php
deleted file mode 100644
index 86e55a2..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_custom_keys_containing_colon_character__1.php
+++ /dev/null
@@ -1,5 +0,0 @@
-
-aaa3abc3bb3abb3abc3acb3
-';
diff --git a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_numeric_keys__1.php b/tests/__snapshots__/ArrayToXmlTest__it_can_handle_numeric_keys__1.php
deleted file mode 100644
index ce1a70c..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_numeric_keys__1.php
+++ /dev/null
@@ -1,5 +0,0 @@
-
-aaa3abc3bb3abb3abc3acb3
-';
diff --git a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_numeric_keys__1.xml b/tests/__snapshots__/ArrayToXmlTest__it_can_handle_numeric_keys__1.xml
deleted file mode 100644
index 1175728..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_numeric_keys__1.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
- aaa
- 3
-
- abc
- 3
-
-
-
- bb
- 3
-
-
- abb
- 3
-
-
- abc
- 3
-
-
-
-
- acb
- 3
-
-
-
-
diff --git a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_numeric_keys__1__1.php b/tests/__snapshots__/ArrayToXmlTest__it_can_handle_numeric_keys__1__1.php
deleted file mode 100644
index 067aa51..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_numeric_keys__1__1.php
+++ /dev/null
@@ -1,5 +0,0 @@
-
-aaa3abc3bb3abb3abc3acb3aaa3abc3bb3abb3abc3acb3
-';
diff --git a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_values_set_as_cdata__1.php b/tests/__snapshots__/ArrayToXmlTest__it_can_handle_values_set_as_cdata__1.php
deleted file mode 100644
index 404ef01..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_values_set_as_cdata__1.php
+++ /dev/null
@@ -1,5 +0,0 @@
-
-STAR WARS]]>tom & jerry]]>
-';
diff --git a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_values_set_as_mixed__1.php b/tests/__snapshots__/ArrayToXmlTest__it_can_handle_values_set_as_mixed__1.php
deleted file mode 100644
index 1e746ec..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__it_can_handle_values_set_as_mixed__1.php
+++ /dev/null
@@ -1,5 +0,0 @@
-
-STAR WARS Figure 1ROBOCOP Figure 2
-';
diff --git a/tests/__snapshots__/ArrayToXmlTest__it_doesnt_pollute_attributes_in_collection_and_sequential_nodes__1.php b/tests/__snapshots__/ArrayToXmlTest__it_doesnt_pollute_attributes_in_collection_and_sequential_nodes__1.php
deleted file mode 100644
index b8ef10b..0000000
--- a/tests/__snapshots__/ArrayToXmlTest__it_doesnt_pollute_attributes_in_collection_and_sequential_nodes__1.php
+++ /dev/null
@@ -1,5 +0,0 @@
-
-ABC
-';