Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
IsLanguageSubtag
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 toPreferredValue
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 convert
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2namespace Apie\IanaValueObjects;
3
4trait IsLanguageSubtag
5{
6    use StaticDataValueObject;
7
8    public function toPreferredValue(): static
9    {
10        $preferred = $this->getFieldValue('Preferred-Value');
11        if ($preferred === null) {
12            return $this;
13        }
14        return new static($preferred);
15    }
16
17    protected function convert(string $input): string
18    {
19        $inputLower = strtolower($input);
20        $data = static::getData();
21        if (!isset($data[$inputLower])) {
22            return $input;
23        }
24
25        return $data[$inputLower]['Subtag'] ?? $input;
26    }
27}