Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
| IsLanguageSubtag | |
100.00% |
16 / 16 |
|
100.00% |
8 / 8 |
14 | |
100.00% |
1 / 1 |
| toPreferredValue | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| isActive | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSubtag | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDescription | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| getAdded | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| getDeprecated | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| getPrefix | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| getMacrolanguage | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\IanaValueObjects\LanguageTag; |
| 3 | |
| 4 | use Apie\Core\ValueObjects\NonEmptyString; |
| 5 | use Apie\IanaValueObjects\IsSanitizingInput; |
| 6 | use Apie\IanaValueObjects\StaticDataValueObject; |
| 7 | use DateTimeImmutable; |
| 8 | |
| 9 | trait IsLanguageSubtag |
| 10 | { |
| 11 | use StaticDataValueObject, IsSanitizingInput { |
| 12 | IsSanitizingInput::convert insteadof StaticDataValueObject; |
| 13 | } |
| 14 | |
| 15 | public function toPreferredValue(): static |
| 16 | { |
| 17 | $preferred = $this->getFieldValue('Preferred-Value'); |
| 18 | if ($preferred === null) { |
| 19 | return $this; |
| 20 | } |
| 21 | return new static($preferred); |
| 22 | } |
| 23 | |
| 24 | public function isActive(): bool |
| 25 | { |
| 26 | return (bool) $this->getFieldValue('Active'); |
| 27 | } |
| 28 | |
| 29 | public function getSubtag(): string |
| 30 | { |
| 31 | return $this->getFieldValue('Subtag'); |
| 32 | } |
| 33 | |
| 34 | public function getDescription(): ?NonEmptyString |
| 35 | { |
| 36 | $description = $this->getFieldValue('Description'); |
| 37 | return $description ? NonEmptyString::fromNative($description) : null; |
| 38 | } |
| 39 | |
| 40 | public function getAdded(): ?DateTimeImmutable |
| 41 | { |
| 42 | $added = $this->getFieldValue('Added'); |
| 43 | return $added ? DateTimeImmutable::createFromFormat('!Y-m-d', $added) : null; |
| 44 | } |
| 45 | |
| 46 | public function getDeprecated(): ?DateTimeImmutable |
| 47 | { |
| 48 | $added = $this->getFieldValue('Deprecated'); |
| 49 | return $added ? DateTimeImmutable::createFromFormat('!Y-m-d', $added) : null; |
| 50 | } |
| 51 | |
| 52 | public function getPrefix(): ?NonEmptyString |
| 53 | { |
| 54 | $prefix = $this->getFieldValue('Prefix'); |
| 55 | return $prefix ? NonEmptyString::fromNative($prefix) : null; |
| 56 | } |
| 57 | |
| 58 | public function getMacrolanguage(): ?NonEmptyString |
| 59 | { |
| 60 | $prefix = $this->getFieldValue('Macrolanguage'); |
| 61 | return $prefix ? NonEmptyString::fromNative($prefix) : null; |
| 62 | } |
| 63 | } |