Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| TopicType | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| shortName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| tryFromString | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace LambdaTwelve\OneRecord\Api; |
| 6 | |
| 7 | use LambdaTwelve\OneRecord\Vocabulary\Generated\Api; |
| 8 | |
| 9 | enum TopicType: string |
| 10 | { |
| 11 | /** The topic is a logistics object URI. */ |
| 12 | case Identifier = Api::LOGISTICS_OBJECT_IDENTIFIER; |
| 13 | |
| 14 | /** The topic is a class IRI (every object of that type). */ |
| 15 | case Type = Api::LOGISTICS_OBJECT_TYPE; |
| 16 | |
| 17 | /** |
| 18 | * The spelling used in query strings: LOGISTICS_OBJECT_IDENTIFIER or LOGISTICS_OBJECT_TYPE. |
| 19 | */ |
| 20 | public function shortName(): string |
| 21 | { |
| 22 | return substr($this->value, \strlen(Api::NAMESPACE)); |
| 23 | } |
| 24 | |
| 25 | public static function tryFromString(string $value): ?self |
| 26 | { |
| 27 | $value = str_starts_with($value, 'api:') ? Api::NAMESPACE . substr($value, 4) : $value; |
| 28 | // The spec allows "#" to be written as "/" in query strings. |
| 29 | $value = str_replace('https://onerecord.iata.org/ns/api/', Api::NAMESPACE, $value); |
| 30 | |
| 31 | return self::tryFrom(str_contains($value, ':') ? $value : Api::NAMESPACE . $value); |
| 32 | } |
| 33 | } |