Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
| IsHttpHeader | |
100.00% |
15 / 15 |
|
100.00% |
8 / 8 |
12 | |
100.00% |
1 / 1 |
| getFieldValue | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| convert | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| getFieldName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getStatus | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| getStructuredType | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| getReference | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getComments | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| isActive | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\IanaValueObjects\HttpHeader; |
| 3 | |
| 4 | use Apie\Core\ValueObjects\NonEmptyString; |
| 5 | |
| 6 | trait IsHttpHeader |
| 7 | { |
| 8 | abstract protected function getFieldValue(string $fieldName): mixed; |
| 9 | |
| 10 | protected static function getData(): array |
| 11 | { |
| 12 | return require __DIR__ . '/../../fixtures/http-fields.php'; |
| 13 | } |
| 14 | |
| 15 | protected function convert(string $input): string |
| 16 | { |
| 17 | $inputLower = strtolower($input); |
| 18 | $data = static::getData(); |
| 19 | if (!isset($data[$inputLower])) { |
| 20 | return $input; |
| 21 | } |
| 22 | |
| 23 | return $data[$inputLower]['Field Name'] ?? $input; |
| 24 | } |
| 25 | |
| 26 | public function getFieldName(): string |
| 27 | { |
| 28 | return $this->getFieldValue('Field Name'); |
| 29 | } |
| 30 | |
| 31 | public function getStatus(): ?HttpHeaderStatus |
| 32 | { |
| 33 | // strtolower as some iana data starts with an uppercase.... |
| 34 | $status = strtolower($this->getFieldValue('Status')); |
| 35 | return $status ? HttpHeaderStatus::from($status) : null; |
| 36 | } |
| 37 | |
| 38 | public function getStructuredType(): ?StructuredType |
| 39 | { |
| 40 | $structuredType = $this->getFieldValue('Structured_Type'); |
| 41 | return $structuredType ? StructuredType::from($structuredType) : null; |
| 42 | } |
| 43 | |
| 44 | public function getReference(): string |
| 45 | { |
| 46 | return $this->getFieldValue('Reference'); |
| 47 | } |
| 48 | |
| 49 | public function getComments(): ?NonEmptyString |
| 50 | { |
| 51 | $comments = $this->getFieldValue('Comments'); |
| 52 | return $comments ? NonEmptyString::fromNative($comments) : null; |
| 53 | } |
| 54 | |
| 55 | public function isActive(): bool |
| 56 | { |
| 57 | return (bool) $this->getFieldValue('Active'); |
| 58 | } |
| 59 | } |