Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Login | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| validate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Validation; |
| 6 | |
| 7 | use Celema\Sire\Contract\Validator; |
| 8 | use Celema\Sire\Result; |
| 9 | use Celema\Sire\Shape; |
| 10 | use Override; |
| 11 | |
| 12 | final class Login implements Validator |
| 13 | { |
| 14 | private Shape $shape; |
| 15 | |
| 16 | public function __construct() |
| 17 | { |
| 18 | $this->shape = new Shape(); |
| 19 | $this->shape |
| 20 | ->add('login', 'string') |
| 21 | ->rules('required', 'maxlen:254') |
| 22 | ->label(__('auth:login-label')); |
| 23 | $this->shape |
| 24 | ->add('password', 'string') |
| 25 | ->rules('required', 'maxlen:512') |
| 26 | ->label(__('auth:password')); |
| 27 | $this->shape |
| 28 | ->add('rememberme', 'bool') |
| 29 | ->empty('missing', 'null') |
| 30 | ->default(false) |
| 31 | ->label(__('auth:remember-me')); |
| 32 | } |
| 33 | |
| 34 | #[Override] |
| 35 | public function validate(array $data): Result |
| 36 | { |
| 37 | return $this->shape->validate($data); |
| 38 | } |
| 39 | } |