| Total Complexity | 5 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 12 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | abstract class Token implements Stringable |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * The token value. |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected string $value; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Mutate the given state |
||
| 23 | * |
||
| 24 | * @param State $state |
||
| 25 | * @return void |
||
| 26 | */ |
||
| 27 | abstract public function mutateState(State $state): void; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Determine whether this token matches the given type |
||
| 31 | * |
||
| 32 | * @param int $type |
||
| 33 | * @return bool |
||
| 34 | */ |
||
| 35 | 357 | public function matches(int $type): bool |
|
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Set the token value |
||
| 42 | * |
||
| 43 | * @param string $value |
||
| 44 | * @return static |
||
| 45 | */ |
||
| 46 | 357 | public function setValue(string $value): static |
|
| 47 | { |
||
| 48 | 357 | $this->value = $value; |
|
| 49 | |||
| 50 | 357 | return $this; |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Determine whether the token is a value |
||
| 55 | * |
||
| 56 | * @return bool |
||
| 57 | */ |
||
| 58 | 357 | public function isValue(): bool |
|
| 59 | { |
||
| 60 | 357 | return (Tokens::TYPES[$this->value[0]] | Tokens::VALUE_ANY) == Tokens::VALUE_ANY; |
|
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Determine whether this token ends a JSON chunk |
||
| 65 | * |
||
| 66 | * @return bool |
||
| 67 | */ |
||
| 68 | 297 | public function endsChunk(): bool |
|
| 69 | { |
||
| 70 | 297 | return false; |
|
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Retrieve the underlying token value |
||
| 75 | * |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | 323 | public function __toString(): string |
|
| 81 | } |
||
| 82 | } |
||
| 83 |