Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.89% covered (warning)
88.89%
8 / 9
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
FormFieldProperty
88.89% covered (warning)
88.89%
8 / 9
50.00% covered (danger)
50.00%
1 / 2
3.01
0.00% covered (danger)
0.00%
0 / 1
 getFallbackText
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 createForProperty
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Core\Translator\ValueObjects;
3
4use Apie\Core\BoundedContext\BoundedContextId;
5use Apie\Core\Identifiers\SnakeCaseSlug;
6use Apie\Core\Lists\ItemHashmap;
7use Apie\Core\Lists\StringList;
8
9final class FormFieldProperty extends AbstractTranslation
10{
11    protected const MIDDLE_REGEX = 'properties\.[^.]+(\.[^.]+)*';
12
13    public function getFallbackText(): string
14    {
15        if (!str_contains($this->middleSection, '.')) {
16            return $this->middleSection;
17        }
18        return strstr($this->middleSection, '.');
19    }
20
21    /**
22     * @param \ReflectionClass<covariant object> $class
23     */
24    public static function createForProperty(
25        StringList $list,
26        \ReflectionClass $class,
27        ?BoundedContextId $boundedContextId = null
28    ): static {
29        return new FormFieldProperty(
30            new TranslationStringPrefix($boundedContextId, SnakeCaseSlug::fromClass($class)),
31            'properties.' . $list->join('.'),
32            new TranslationStringSuffix(),
33            new ItemHashmap()
34        );
35    }
36}