Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Username | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| isValid | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Engelsystem\Http\Validation\Rules; |
| 6 | |
| 7 | use Respect\Validation\Rules\Core\Simple; |
| 8 | use Respect\Validation\Validator; |
| 9 | use RuntimeException; |
| 10 | |
| 11 | /** |
| 12 | * Username validation. |
| 13 | * Usernames must have 1-24 chars and NOT match the regular expression defined under the config key "username_regex". |
| 14 | */ |
| 15 | class Username extends Simple |
| 16 | { |
| 17 | public function isValid(mixed $input): bool |
| 18 | { |
| 19 | $regex = config('username_regex'); |
| 20 | |
| 21 | if ($regex === null) { |
| 22 | throw new RuntimeException('username_regex not set in config'); |
| 23 | } |
| 24 | |
| 25 | return Validator::length(1, 24)->validate($input) |
| 26 | && Validator::not(Validator::regex($regex))->validate($input); |
| 27 | } |
| 28 | } |