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