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