Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| IsStringWithRegexValueObject | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| validate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| getRegularExpression | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | namespace Apie\Core\ValueObjects; |
| 3 | |
| 4 | use Apie\Core\Attributes\CmsValidationCheck; |
| 5 | use Apie\Core\ValueObjects\Exceptions\InvalidStringForValueObjectException; |
| 6 | use ReflectionClass; |
| 7 | |
| 8 | #[CmsValidationCheck(patternMethod: 'getRegularExpression')] |
| 9 | trait IsStringWithRegexValueObject |
| 10 | { |
| 11 | use IsStringValueObject; |
| 12 | public static function validate(string $input): void |
| 13 | { |
| 14 | if (!preg_match(static::getRegularExpression(), $input)) { |
| 15 | throw new InvalidStringForValueObjectException($input, new ReflectionClass(self::class)); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | abstract public static function getRegularExpression(): string; |
| 20 | } |