Skip to content

Commit

Permalink
nipicks
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Apr 23, 2021
1 parent 934a2a9 commit e46df26
Show file tree
Hide file tree
Showing 17 changed files with 9 additions and 107 deletions.
20 changes: 6 additions & 14 deletions src/ArrayToXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
}
}
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions tests/ArrayToXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class ArrayToXmlTest extends TestCase
{
use MatchesSnapshots;

/** @test array */
protected $testArray = [];
protected array $testArray = [];

public function setUp(): void
{
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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' => [
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit e46df26

Please sign in to comment.