Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| LoginDTO | |
100.00% |
23 / 23 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| fromRequest | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| getKey | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Login\DTOs; |
| 4 | |
| 5 | use Illuminate\Foundation\Http\FormRequest; |
| 6 | use Illuminate\Support\Str; |
| 7 | |
| 8 | use Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 9 | |
| 10 | readonly final class LoginDTO implements DataTransferObjectInterface |
| 11 | { |
| 12 | private string $email; |
| 13 | private string $password; |
| 14 | private int $access_level; |
| 15 | private int $sector; |
| 16 | public ?string $expo_token; |
| 17 | |
| 18 | public function __construct(array $args) |
| 19 | { |
| 20 | $this->email = Str::lower($args['email']); |
| 21 | $this->password = $args['password']; |
| 22 | $this->access_level = $args['access_level']; |
| 23 | $this->sector = $args['sector']; |
| 24 | $this->expo_token = $args['expo_token'] ?? null; |
| 25 | } |
| 26 | |
| 27 | public function toArray(): array |
| 28 | { |
| 29 | return [ |
| 30 | 'email' => $this->email, |
| 31 | 'password' => $this->password, |
| 32 | 'access_level' => $this->access_level, |
| 33 | 'sector' => $this->sector, |
| 34 | 'expo_token' => $this->expo_token, |
| 35 | ]; |
| 36 | } |
| 37 | |
| 38 | public static function fromRequest(FormRequest $request): self |
| 39 | { |
| 40 | return new self([ |
| 41 | 'email' => $request->validated('email'), |
| 42 | 'password' => $request->validated('password'), |
| 43 | 'access_level' => $request->validated('access_level'), |
| 44 | 'sector' => $request->validated('sector'), |
| 45 | 'expo_token' => $request->validated('expo_token') |
| 46 | ]); |
| 47 | } |
| 48 | |
| 49 | public function getKey(): array |
| 50 | { |
| 51 | return [ |
| 52 | 'email' => $this->email, |
| 53 | 'password' => $this->password, |
| 54 | ]; |
| 55 | } |
| 56 | } |