Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Login | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
11 / 11 |
|
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 Celemas\Sire\Contract\Validator; |
| 8 | use Celemas\Sire\Result; |
| 9 | use Celemas\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(_('Username or email')); |
| 23 | $this->shape->add('password', 'string')->rules('required', 'maxlen:512')->label(_('Password')); |
| 24 | $this->shape |
| 25 | ->add('rememberme', 'bool') |
| 26 | ->empty('missing', 'null') |
| 27 | ->default(false) |
| 28 | ->label(_('remember me')); |
| 29 | } |
| 30 | |
| 31 | #[Override] |
| 32 | public function validate(array $data): Result |
| 33 | { |
| 34 | return $this->shape->validate($data); |
| 35 | } |
| 36 | } |