| Total Complexity | 7 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | final class ExampleRegistry implements RegistryInterface |
||
| 10 | { |
||
| 11 | /** @var ExampleInterface[] */ |
||
| 12 | private $examples = []; |
||
| 13 | |||
| 14 | public function setExample(ExampleInterface $example): void |
||
| 15 | { |
||
| 16 | if ($example->getName()->isUnnamed()) { |
||
| 17 | $this->examples[] = $example; |
||
| 18 | return; |
||
| 19 | } |
||
| 20 | |||
| 21 | $this->examples[$example->getName()->getCompleteName()] = $example; |
||
| 22 | } |
||
| 23 | |||
| 24 | public function hasExample(NameInterface $name): bool |
||
| 25 | { |
||
| 26 | return !$name->isUnnamed() && isset($this->examples[$name->getCompleteName()]); |
||
| 27 | } |
||
| 28 | |||
| 29 | public function getExample(NameInterface $name): ExampleInterface |
||
| 30 | { |
||
| 31 | if (!isset($this->examples[$name->getCompleteName()])) { |
||
| 32 | throw new \RuntimeException("Example '{$name->getShortName()}' does not exist"); |
||
| 33 | } |
||
| 34 | |||
| 35 | return $this->examples[$name->getCompleteName()]; |
||
| 36 | } |
||
| 37 | |||
| 38 | public function getExamples(): array |
||
| 41 | } |
||
| 42 | } |
||
| 43 |