Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
EventRecurrenceTransformer
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
10
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
1
 transformRead
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 transformWrite
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
6
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 * Event Recurrence UiType Transformer.
15 *
16 * Handles UiType: event_recurrence.
17 * Validates, trims, and normalizes RFC 5545 iCalendar recurrence rule (RRULE) strings.
18 *
19 * @package App\Core\Engine\Application\Transformer
20 */
21final class EventRecurrenceTransformer implements UiTypeTransformerInterface
22{
23    /** Supported frequencies in RFC 5545. */
24    public const array VALID_FREQUENCIES = ['DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY'];
25
26    /** {@inheritdoc} */
27    public function supports(string $uitypeName): bool
28    {
29        return $uitypeName === 'event_recurrence';
30    }
31
32    /** {@inheritdoc} */
33    public function transformRead(mixed $rawValue, FieldMetadata $field): string
34    {
35        if ($rawValue === null || $rawValue === '') {
36            return '';
37        }
38
39        return trim((string) $rawValue);
40    }
41
42    /** {@inheritdoc} */
43    public function transformWrite(mixed $inputValue, FieldMetadata $field): ?string
44    {
45        if ($inputValue === null || $inputValue === '') {
46            return null;
47        }
48
49        $rule = trim((string) $inputValue);
50        $upper = strtoupper($rule);
51        if ($upper === '' || $upper === 'NONE' || !str_contains($upper, 'FREQ=')) {
52            return null;
53        }
54
55        return $rule;
56    }
57}