Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| EmailInputTransformer | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| transformWrite | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Core\Engine\Application\Transformer; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Core\Engine\Domain\Model\FieldMetadata; |
| 12 | |
| 13 | /** |
| 14 | * Email Input UiType Transformer. |
| 15 | * |
| 16 | * Handles UiType: email_input with email validation and normalization. |
| 17 | * |
| 18 | * @package App\Core\Engine\Application\Transformer |
| 19 | */ |
| 20 | final class EmailInputTransformer extends AbstractStringTransformer |
| 21 | { |
| 22 | /** {@inheritdoc} */ |
| 23 | public function supports(string $uitypeName): bool |
| 24 | { |
| 25 | return $uitypeName === 'email_input' || $uitypeName === 'email'; |
| 26 | } |
| 27 | |
| 28 | /** {@inheritdoc} */ |
| 29 | public function transformWrite(mixed $inputValue, FieldMetadata $field): mixed |
| 30 | { |
| 31 | $email = is_scalar($inputValue) ? mb_strtolower(trim((string) $inputValue)) : ''; |
| 32 | if ($email === '') { |
| 33 | return null; |
| 34 | } |
| 35 | |
| 36 | $validated = filter_var($email, FILTER_VALIDATE_EMAIL); |
| 37 | |
| 38 | return $validated !== false ? (string) $validated : null; |
| 39 | } |
| 40 | } |