Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| EmailLocalPart | |
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
4.59 | |
0.00% |
0 / 1 |
| createRandom | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| validate | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
4.12 | |||
| 1 | <?php |
| 2 | namespace Apie\CommonValueObjects; |
| 3 | |
| 4 | use Apie\Core\Attributes\CmsSingleInput; |
| 5 | use Apie\Core\Attributes\Description; |
| 6 | use Apie\Core\Attributes\FakeMethod; |
| 7 | use Apie\Core\ValueObjects\Exceptions\InvalidStringForValueObjectException; |
| 8 | use Apie\Core\ValueObjects\Interfaces\StringValueObjectInterface; |
| 9 | use Apie\Core\ValueObjects\IsStringValueObject; |
| 10 | use Faker\Generator; |
| 11 | use ReflectionClass; |
| 12 | |
| 13 | #[FakeMethod('createRandom')] |
| 14 | #[CmsSingleInput(['local-part', 'text'])] |
| 15 | #[Description('Represents the local part of an e-mail address')] |
| 16 | class EmailLocalPart implements StringValueObjectInterface |
| 17 | { |
| 18 | use IsStringValueObject; |
| 19 | |
| 20 | public static function createRandom(Generator $generator): self |
| 21 | { |
| 22 | return new static(str_replace(' ', '', $generator->userName())); |
| 23 | } |
| 24 | |
| 25 | public static function validate(string $input): void |
| 26 | { |
| 27 | if ($input === '' || preg_match('/^(?=.{1,64}$)[A-Za-z0-9.!#$%&\'*+\/?^_`{|}~-]+$/', $input) !== 1) { |
| 28 | throw new InvalidStringForValueObjectException($input, new ReflectionClass(__CLASS__)); |
| 29 | } |
| 30 | } |
| 31 | } |