Untitled

mail@pastecode.io avatar
unknown
php
a year ago
465 B
10
Indexable
Never
<?php

class UserSerializer
{
    public function serialize(User $user): array
    {
        return [
            'id' => $user->id,
            'first_name' => $user->firstName,
            'last_name' => $user->lastName,
        ];
    }

    /**
     * @param User[] $users
     */
    public function serializeList(array $users): array
    {
        return array_map(
            fn (User $user) => $this->serialize($user),
            $users
        );
    }
}