From 55caaf38a223c6542bb8f8ef5565b89eb69d39e0 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Fri, 4 Oct 2024 14:14:15 -0400 Subject: [PATCH] nitpick --- src/Tags/Dictionary/Dictionary.php | 21 +++++++++++---------- src/Tags/Dictionary/DictionaryItem.php | 3 +-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Tags/Dictionary/Dictionary.php b/src/Tags/Dictionary/Dictionary.php index b91e594b7b..6fbb0e55be 100644 --- a/src/Tags/Dictionary/Dictionary.php +++ b/src/Tags/Dictionary/Dictionary.php @@ -24,9 +24,7 @@ class Dictionary extends Tags */ public function wildcard($tag) { - $this->params['handle'] = $tag; - - return $this->index(); + return $this->loop($tag); } /** @@ -34,7 +32,12 @@ public function wildcard($tag) */ public function index() { - if (! $handle = $this->params->pull('handle')) { + return $this->loop($this->params->pull('handle')); + } + + private function loop($handle) + { + if (! $handle) { return []; } @@ -44,18 +47,16 @@ public function index() throw new DictionaryNotFoundException($handle); } - $options = collect($dictionary->options($search)) - ->map(fn ($label, $value) => new DictionaryItem(array_merge(['label' => $label, 'value' => $value], $dictionary->get($value)->extra()))) + $options = (new DataCollection($dictionary->options($search))) + ->map(fn ($label, $value) => new DictionaryItem($dictionary->get($value)->toArray())) ->values(); - $query = (new ItemQueryBuilder)->withItems(new DataCollection($options)); + $query = (new ItemQueryBuilder)->withItems($options); $this->queryConditions($query); $this->queryOrderBys($query); $this->queryScopes($query); - $options = $this->results($query); - - return $this->output($options); + return $this->output($this->results($query)); } } diff --git a/src/Tags/Dictionary/DictionaryItem.php b/src/Tags/Dictionary/DictionaryItem.php index d98e135c8d..f155578e23 100644 --- a/src/Tags/Dictionary/DictionaryItem.php +++ b/src/Tags/Dictionary/DictionaryItem.php @@ -12,7 +12,6 @@ class DictionaryItem implements Arrayable public function __construct(public array $data) { - } public function get($key, $default = null) @@ -22,6 +21,6 @@ public function get($key, $default = null) public function toArray() { - return array_merge($this->data, $this->supplements() ?? []); + return array_merge($this->data, $this->supplements ?? []); } }