Skip to content

Commit

Permalink
Added more types (spatie#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperDJ authored Nov 24, 2022
1 parent e4cb02b commit 670ede8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/ArrayToXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public function __construct(
array $array,
string | array $rootElement = '',
bool $replaceSpacesByUnderScoresInKeyNames = true,
?string $xmlEncoding = null,
string | null $xmlEncoding = null,
string $xmlVersion = '1.0',
array $domProperties = [],
?bool $xmlStandalone = null
bool | null $xmlStandalone = null
) {
$this->document = new DOMDocument($xmlVersion, $xmlEncoding ?? '');

Expand All @@ -38,7 +38,7 @@ public function __construct(

$this->replaceSpacesByUnderScoresInKeyNames = $replaceSpacesByUnderScoresInKeyNames;

if ($this->isArrayAllKeySequential($array) && ! empty($array)) {
if (! empty($array) && $this->isArrayAllKeySequential($array)) {
throw new DOMException('Invalid Character Error');
}

Expand Down Expand Up @@ -177,14 +177,14 @@ protected function convertElement(DOMElement $element, mixed $value): void
}
}

protected function addNumericNode(DOMElement $element, $value): void
protected function addNumericNode(DOMElement $element, mixed $value): void
{
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, string $key, mixed $value): void
{
if ($this->replaceSpacesByUnderScoresInKeyNames) {
$key = str_replace(' ', '_', $key);
Expand All @@ -195,7 +195,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, mixed $value): void
{
if ($element->childNodes->length === 0 && $element->attributes->length === 0) {
$this->convertElement($element, $value);
Expand All @@ -208,7 +208,7 @@ protected function addCollectionNode(DOMElement $element, $value): void
$this->convertElement($child, $value);
}

protected function addSequentialNode(DOMElement $element, $value): void
protected function addSequentialNode(DOMElement $element, mixed $value): void
{
if (empty($element->nodeValue) && ! is_numeric($element->nodeValue)) {
$element->nodeValue = htmlspecialchars($value);
Expand Down Expand Up @@ -245,7 +245,7 @@ protected function addAttributes(DOMElement $element, array $data): void
}
}

protected function createRootElement($rootElement): DOMElement
protected function createRootElement(string|array $rootElement): DOMElement
{
if (is_string($rootElement)) {
$rootElementName = $rootElement ?: 'root';
Expand Down

0 comments on commit 670ede8

Please sign in to comment.