| Total Complexity | 3 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 5 | class RepresentationUniquenessGuard |
||
| 6 | { |
||
| 7 | private static array $keys = []; |
||
| 8 | |||
| 9 | public function ensureUnique(RepresentationInterface $representation): void |
||
| 10 | { |
||
| 11 | $key = $this->generateKey($representation); |
||
| 12 | |||
| 13 | if (isset(self::$keys[$key])) { |
||
| 14 | throw new DuplicateRepresentationException("Duplicate '$key' representation"); |
||
| 15 | } |
||
| 16 | |||
| 17 | self::$keys[$key] = true; |
||
| 18 | } |
||
| 19 | |||
| 20 | private function generateKey(RepresentationInterface $representation): string |
||
| 25 | } |
||
| 26 | } |
||
| 27 |