Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
UsersController
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 user
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Controllers\Api;
6
7use Engelsystem\Controllers\Api\Resources\UserDetailResource;
8use Engelsystem\Controllers\Api\Resources\UserResource;
9use Engelsystem\Http\Request;
10use Engelsystem\Http\Response;
11
12class UsersController extends ApiController
13{
14    use UsesAuth;
15
16    public function user(Request $request): Response
17    {
18        $id = $request->getAttribute('user_id');
19        $user = $this->getUser($id);
20
21        $userData = $user->id == $this->auth->user()->id ? new UserDetailResource($user) : new UserResource($user);
22        $data = ['data' => $userData->toArray()];
23        return $this->response
24            ->withContent(json_encode($data));
25    }
26}