. */ declare(strict_types=1); namespace FireflyIII\Transformers; use FireflyIII\Models\Role; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; use Log; /** * Class UserTransformer */ class UserTransformer extends AbstractTransformer { /** @var UserRepositoryInterface */ private $repository; /** * UserTransformer constructor. * * @codeCoverageIgnore */ public function __construct() { $this->repository = app(UserRepositoryInterface::class); if ('testing' === config('app.env')) { Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this))); } } /** * Transform user. * * @param User $user * * @return array */ public function transform(User $user): array { return [ 'id' => (int)$user->id, 'created_at' => $user->created_at->toAtomString(), 'updated_at' => $user->updated_at->toAtomString(), 'email' => $user->email, 'blocked' => 1 === (int)$user->blocked, 'blocked_code' => '' === $user->blocked_code ? null : $user->blocked_code, 'role' => $this->repository->getRoleByUser($user), 'links' => [ [ 'rel' => 'self', 'uri' => '/users/' . $user->id, ], ], ]; } }