Skip to content

Commit 91cf71a

Browse files
committed
FP for the win
1 parent 65ad5cc commit 91cf71a

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

src/Collection/AbstractCollection.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,15 @@ final public function getItems(): array
112112
*/
113113
final public function jsonSerialize(): array
114114
{
115-
$items = [];
116-
foreach ($this->items as $item) {
117-
$items[] = $item->jsonSerialize();
118-
}
119-
120115
return [
121116
'offset' => $this->offset,
122117
'limit' => $this->limit,
123118
'filters' => $this->filters,
124119
'sort' => $this->sort,
125-
'items' => $items,
120+
'items' => array_map(
121+
static fn (ModelInterface $model) => $model->jsonSerialize(),
122+
$this->items
123+
),
126124
'count' => $this->count,
127125
];
128126
}

src/Dto/Collection/AbstractCollectionResponse.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,15 @@ abstract class AbstractCollectionResponse implements CollectionResponseInterface
6262
*/
6363
final public function jsonSerialize(): array
6464
{
65-
$items = [];
66-
foreach ($this->items as $item) {
67-
$items[] = $item->jsonSerialize();
68-
}
69-
7065
return [
7166
'offset' => $this->offset,
7267
'limit' => $this->limit,
7368
'filters' => $this->getFilters()->jsonSerialize(),
7469
'sort' => $this->getSort()->jsonSerialize(),
75-
'items' => $items,
70+
'items' => array_map(
71+
static fn (ModelResponseInterface $modelResponse) => $modelResponse->jsonSerialize(),
72+
$this->items
73+
),
7674
'count' => $this->count,
7775
'_type' => $this->_type,
7876
'_links' => $this->_links,

0 commit comments

Comments
 (0)