| Total Complexity | 9 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class Table implements TableInterface |
||
| 10 | { |
||
| 11 | private $map = []; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @param int $symbolId |
||
| 15 | * @param int $tokenId |
||
| 16 | * @param int $productionIndex |
||
| 17 | * @throws Exception |
||
| 18 | */ |
||
| 19 | public function addProduction(int $symbolId, int $tokenId, int $productionIndex): void |
||
| 20 | { |
||
| 21 | if ($this->hasProduction($symbolId, $tokenId)) { |
||
| 22 | throw new Exception("Production for [{$symbolId}:{$tokenId}] is already defined"); |
||
| 23 | } |
||
| 24 | $this->map[$symbolId][$tokenId] = $productionIndex; |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param int $symbolId |
||
| 29 | * @param int $tokenId |
||
| 30 | * @return int |
||
| 31 | * @throws Exception |
||
| 32 | */ |
||
| 33 | public function getProductionIndex(int $symbolId, int $tokenId): int |
||
| 34 | { |
||
| 35 | if (!$this->hasProduction($symbolId, $tokenId)) { |
||
| 36 | throw new Exception("Production for [{$symbolId}:{$tokenId}] is not defined"); |
||
| 37 | } |
||
| 38 | return $this->map[$symbolId][$tokenId]; |
||
| 39 | } |
||
| 40 | |||
| 41 | public function getExpectedTokenList(int $symbolId): array |
||
| 42 | { |
||
| 43 | return isset($this->map[$symbolId]) ? array_keys($this->map[$symbolId]) : []; |
||
| 44 | } |
||
| 45 | |||
| 46 | public function hasProduction(int $symbolId, int $tokenId): bool |
||
| 47 | { |
||
| 48 | return isset($this->map[$symbolId][$tokenId]); |
||
| 49 | } |
||
| 50 | |||
| 51 | public function exportMap(): array |
||
| 52 | { |
||
| 53 | return $this->map; |
||
| 54 | } |
||
| 55 | |||
| 56 | public function importMap(array $map): void |
||
| 59 | } |
||
| 60 | } |
||
| 61 |