Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
14.29% |
1 / 7 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CreateFormFieldProperty | |
14.29% |
1 / 7 |
|
50.00% |
1 / 2 |
4.52 | |
0.00% |
0 / 1 |
| getFallbackText | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createForProperty | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Translator\ValueObjects; |
| 3 | |
| 4 | use Apie\Core\BoundedContext\BoundedContextId; |
| 5 | use Apie\Core\Identifiers\SnakeCaseSlug; |
| 6 | use Apie\Core\Lists\ItemHashmap; |
| 7 | use Apie\Core\Lists\StringList; |
| 8 | |
| 9 | /** |
| 10 | * Translation for a form field on the create resource form. |
| 11 | */ |
| 12 | final class CreateFormFieldProperty extends AbstractTranslation |
| 13 | { |
| 14 | protected const MIDDLE_REGEX = 'create\.[^.]+(\.[^.]+)*'; |
| 15 | |
| 16 | public function getFallbackText(): string |
| 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 CreateFormFieldProperty( |
| 30 | new TranslationStringPrefix($boundedContextId, SnakeCaseSlug::fromClass($class)), |
| 31 | 'create.' . $list->join('.'), |
| 32 | new TranslationStringSuffix(), |
| 33 | new ItemHashmap() |
| 34 | ); |
| 35 | } |
| 36 | } |