Skip to content

Commit 7e5d0b1

Browse files
authored
Merge pull request #63 from codebar-ag/rewrite-parsevalue
Refactor ParseValue field method
2 parents ca30f5f + 501fa4d commit 7e5d0b1

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/Support/ParseValue.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Carbon\Carbon;
66
use CodebarAg\DocuWare\DTO\TableRow;
7+
use Illuminate\Support\Arr;
78
use Illuminate\Support\Collection;
89
use Illuminate\Support\Str;
910

@@ -23,21 +24,21 @@ public static function field(
2324
?array $field,
2425
null|int|float|Carbon|string|Collection $default = null,
2526
): null|int|float|Carbon|string|Collection {
26-
if (! $field) {
27+
if (! $field || $field['IsNull']) {
2728
return $default;
2829
}
2930

30-
if ($field['IsNull']) {
31-
return $default;
32-
}
33-
34-
return match ($field['ItemElementName']) {
35-
'Int' => (int) $field['Item'],
36-
'Decimal' => (float) $field['Item'],
37-
'Date', 'DateTime' => self::date($field['Item']),
38-
'Keywords' => implode(', ', $field['Item']['Keyword']),
39-
'Table' => self::table($field['Item']),
40-
default => (string) $field['Item'],
31+
$item = Arr::get($field, 'Item');
32+
$itemElementName = Arr::get($field, 'ItemElementName');
33+
34+
return match ($itemElementName) {
35+
'Int' => (int) $item,
36+
'String' => (string) $item,
37+
'Decimal' => (float) $item,
38+
'Date', 'DateTime' => self::date($item),
39+
'Keywords' => Arr::join($item['Keyword'], ', '),
40+
'Table' => self::table($item),
41+
default => $default,
4142
};
4243
}
4344

0 commit comments

Comments
 (0)