From 501fa4d9529c69943df74e7bac7fe687abb5f1a6 Mon Sep 17 00:00:00 2001 From: faissaloux Date: Thu, 12 Jan 2023 12:48:33 +0100 Subject: [PATCH] refactor ParseValue field method --- src/Support/ParseValue.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Support/ParseValue.php b/src/Support/ParseValue.php index fad3acc8..8676eb9e 100644 --- a/src/Support/ParseValue.php +++ b/src/Support/ParseValue.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use CodebarAg\DocuWare\DTO\TableRow; +use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Str; @@ -23,21 +24,21 @@ public static function field( ?array $field, null|int|float|Carbon|string|Collection $default = null, ): null|int|float|Carbon|string|Collection { - if (! $field) { + if (! $field || $field['IsNull']) { return $default; } - if ($field['IsNull']) { - return $default; - } - - return match ($field['ItemElementName']) { - 'Int' => (int) $field['Item'], - 'Decimal' => (float) $field['Item'], - 'Date', 'DateTime' => self::date($field['Item']), - 'Keywords' => implode(', ', $field['Item']['Keyword']), - 'Table' => self::table($field['Item']), - default => (string) $field['Item'], + $item = Arr::get($field, 'Item'); + $itemElementName = Arr::get($field, 'ItemElementName'); + + return match ($itemElementName) { + 'Int' => (int) $item, + 'String' => (string) $item, + 'Decimal' => (float) $item, + 'Date', 'DateTime' => self::date($item), + 'Keywords' => Arr::join($item['Keyword'], ', '), + 'Table' => self::table($item), + default => $default, }; }