| Total Complexity | 11 |
| Total Lines | 64 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | class IDType extends ScalarType |
||
| 21 | { |
||
| 22 | /** @var string */ |
||
| 23 | public $name = 'ID'; |
||
| 24 | |||
| 25 | /** @var string */ |
||
| 26 | public $description = |
||
| 27 | 'The `ID` scalar type represents a unique identifier, often used to |
||
| 28 | refetch an object or as key for a cache. The ID type appears in a JSON |
||
| 29 | response as a String; however, it is not intended to be human-readable. |
||
| 30 | When expected as an input type, any string (such as `"4"`) or integer |
||
| 31 | (such as `4`) input value will be accepted as an ID.'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param mixed $value |
||
| 35 | * |
||
| 36 | * @return string |
||
| 37 | * |
||
| 38 | * @throws Error |
||
| 39 | */ |
||
| 40 | 8 | public function serialize($value) |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param mixed $value |
||
| 55 | * |
||
| 56 | * @return string |
||
| 57 | * |
||
| 58 | * @throws Error |
||
| 59 | */ |
||
| 60 | 4 | public function parseValue($value) |
|
| 61 | { |
||
| 62 | 4 | if (is_string($value) || is_int($value)) { |
|
| 63 | 1 | return (string) $value; |
|
| 64 | } |
||
| 65 | 3 | throw new Error('ID cannot represent value: ' . Utils::printSafe($value)); |
|
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param Node $valueNode |
||
| 70 | * @param mixed[]|null $variables |
||
| 71 | * |
||
| 72 | * @return string|null |
||
| 73 | * |
||
| 74 | * @throws Exception |
||
| 75 | */ |
||
| 76 | 8 | public function parseLiteral($valueNode, ?array $variables = null) |
|
| 84 | } |
||
| 85 | } |
||
| 86 |