Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| LoginForm | |
100.00% |
14 / 14 |
|
100.00% |
5 / 5 |
9 | |
100.00% |
1 / 1 |
| load | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| validate | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| getUsername | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPassword | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isRememberMe | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Domain\Auth\Form; |
| 6 | |
| 7 | class LoginForm |
| 8 | { |
| 9 | private string $username = ''; |
| 10 | private string $password = ''; |
| 11 | private bool $rememberMe = false; |
| 12 | |
| 13 | /** |
| 14 | * @param array<string, mixed> $data |
| 15 | */ |
| 16 | public function load(array $data): self |
| 17 | { |
| 18 | $username = $data['username'] ?? ''; |
| 19 | $this->username = trim(is_string($username) ? $username : ''); |
| 20 | |
| 21 | $password = $data['password'] ?? ''; |
| 22 | $this->password = is_string($password) ? $password : ''; |
| 23 | |
| 24 | $this->rememberMe = !empty($data['remember_me']); |
| 25 | |
| 26 | return $this; |
| 27 | } |
| 28 | |
| 29 | public function validate(): ?string |
| 30 | { |
| 31 | if ($this->username === '') { |
| 32 | return 'Login jest wymagany.'; |
| 33 | } |
| 34 | |
| 35 | if ($this->password === '') { |
| 36 | return 'Hasło jest wymagane.'; |
| 37 | } |
| 38 | |
| 39 | return null; |
| 40 | } |
| 41 | |
| 42 | public function getUsername(): string |
| 43 | { |
| 44 | return $this->username; |
| 45 | } |
| 46 | |
| 47 | public function getPassword(): string |
| 48 | { |
| 49 | return $this->password; |
| 50 | } |
| 51 | |
| 52 | public function isRememberMe(): bool |
| 53 | { |
| 54 | return $this->rememberMe; |
| 55 | } |
| 56 | } |