Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
57.14% |
8 / 14 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ValidatorBase | |
57.14% |
8 / 14 |
|
66.67% |
2 / 3 |
6.97 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
isEmail | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
isWebsite | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Domain; |
6 | |
7 | use PeServer\Core\TrueKeeper; |
8 | use PeServer\Core\Mvc\Validator; |
9 | use PeServer\Core\Text; |
10 | use PeServer\Core\Mvc\IValidationReceiver; |
11 | |
12 | abstract class ValidatorBase |
13 | { |
14 | public const EMAIL_LENGTH = 254; |
15 | public const WEBSITE_LENGTH = 2083; |
16 | |
17 | protected IValidationReceiver $receiver; |
18 | protected Validator $validator; |
19 | |
20 | protected function __construct(IValidationReceiver $receiver, Validator $validator) |
21 | { |
22 | $this->receiver = $receiver; |
23 | $this->validator = $validator; |
24 | } |
25 | |
26 | final public function isEmail(string $key, ?string $value): bool |
27 | { |
28 | if ($this->validator->isNotWhiteSpace($key, $value)) { |
29 | $trueKeeper = new TrueKeeper(); |
30 | |
31 | $trueKeeper->state = $this->validator->inLength($key, self::EMAIL_LENGTH, $value); |
32 | $trueKeeper->state = $this->validator->isEmail($key, $value); |
33 | |
34 | return $trueKeeper->state; |
35 | } |
36 | |
37 | return true; |
38 | } |
39 | |
40 | final public function isWebsite(string $key, ?string $value): bool |
41 | { |
42 | if (!Text::isNullOrWhiteSpace($value)) { |
43 | $trueKeeper = new TrueKeeper(); |
44 | |
45 | $trueKeeper->state = $this->validator->inLength($key, self::WEBSITE_LENGTH, $value); |
46 | $trueKeeper->state = $this->validator->isWebsite($key, $value); |
47 | |
48 | return $trueKeeper->state; |
49 | } |
50 | |
51 | return true; |
52 | } |
53 | } |