Skip to content

Commit cf434e7

Browse files
committed
Fix PhpStan error
1 parent e428d65 commit cf434e7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Convertor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public static function covertToArray(string $xml): array
2121
$output = (array) Helper::domNodeToArray($root);
2222
$output['@root'] = $root->tagName;
2323

24-
return $output ?? [];
24+
return $output;
2525
}
2626
}

src/Helper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,21 @@ public static function domNodeToArray($node): mixed
3535
if (!isset($output[$t])) {
3636
$output[$t] = [];
3737
}
38+
/** @phpstan-ignore-next-line */
3839
if (is_array($v) && empty($v)) {
3940
$v = '';
4041
}
4142
$output[$t][] = $v;
43+
/** @phpstan-ignore-next-line */
4244
} elseif ($v || $v === '0') {
4345
$output = (string) $v;
4446
}
4547
}
46-
if ($node->attributes->length && !is_array($output)) { // has attributes but isn't an array
48+
if ($node->attributes->length > 0 && !is_array($output)) { // has attributes but isn't an array
4749
$output = ['@content' => $output]; // change output into an array.
4850
}
4951
if (is_array($output)) {
50-
if ($node->attributes->length) {
52+
if ($node->attributes->length > 0) {
5153
$a = [];
5254
foreach ($node->attributes as $attrName => $attrNode) {
5355
$a[$attrName] = (string) $attrNode->value;

0 commit comments

Comments
 (0)