Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
UsesAuth
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 setAuth
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUser
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Controllers\Api;
6
7use Engelsystem\Helpers\Authenticator;
8use Engelsystem\Models\User\User;
9
10trait UsesAuth
11{
12    protected ?Authenticator $auth = null;
13
14    public function setAuth(Authenticator $auth): void
15    {
16        $this->auth = $auth;
17    }
18
19    protected function getUser(int|string $userId): ?User
20    {
21        if ($userId == 'self' && $this->auth) {
22            return $this->auth->user();
23        }
24
25        return User::findOrFail($userId);
26    }
27}