| Total Complexity | 9 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class Token implements AttributeListInterface |
||
| 12 | { |
||
| 13 | private $type; |
||
| 14 | |||
| 15 | private $isEoi; |
||
| 16 | |||
| 17 | private $attributeList = []; |
||
| 18 | |||
| 19 | public function __construct(int $type, bool $isEoi) |
||
| 20 | { |
||
| 21 | $this->type = $type; |
||
| 22 | $this->isEoi = $isEoi; |
||
| 23 | } |
||
| 24 | |||
| 25 | public function getType(): int |
||
| 26 | { |
||
| 27 | return $this->type; |
||
| 28 | } |
||
| 29 | |||
| 30 | public function isEoi(): bool |
||
| 31 | { |
||
| 32 | return $this->isEoi; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $name |
||
| 37 | * @param mixed $value |
||
| 38 | * @throws Exception |
||
| 39 | */ |
||
| 40 | public function setAttribute(string $name, $value): void |
||
| 41 | { |
||
| 42 | if (isset($this->attributeList[$name])) { |
||
| 43 | throw new Exception("Token attribute '{$name}' is already set"); |
||
| 44 | } |
||
| 45 | $this->attributeList[$name] = $value; |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param string $name |
||
| 50 | * @return mixed |
||
| 51 | * @throws Exception |
||
| 52 | */ |
||
| 53 | public function getAttribute(string $name) |
||
| 54 | { |
||
| 55 | if (!$this->attributeExists($name)) { |
||
| 56 | throw new Exception("Token attribute '{$name}' is not defined"); |
||
| 57 | } |
||
| 58 | return $this->attributeList[$name]; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @param string $name |
||
| 63 | * @return bool |
||
| 64 | */ |
||
| 65 | public function attributeExists(string $name): bool |
||
| 66 | { |
||
| 67 | return isset($this->attributeList[$name]); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @return array|AttributeListShortcut |
||
| 72 | */ |
||
| 73 | public function getShortcut(): AttributeListShortcut |
||
| 76 | } |
||
| 77 | } |
||
| 78 |