| Total Complexity | 9 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | final class LocatorBuilder implements LocatorBuilderInterface |
||
| 11 | { |
||
| 12 | |||
| 13 | private $locator; |
||
| 14 | |||
| 15 | private $referenceFactory; |
||
| 16 | |||
| 17 | private $references = []; |
||
| 18 | |||
| 19 | 1 | public static function create(): LocatorBuilderInterface |
|
| 20 | { |
||
| 21 | 1 | return new self(new ReferenceFactory); |
|
| 22 | } |
||
| 23 | |||
| 24 | 14 | public function __construct(ReferenceFactoryInterface $referenceFactory) |
|
| 25 | { |
||
| 26 | 14 | $this->referenceFactory = $referenceFactory; |
|
| 27 | 14 | } |
|
| 28 | |||
| 29 | 10 | public function addReference(string $text): void |
|
| 30 | { |
||
| 31 | 10 | if (isset($this->locator)) { |
|
| 32 | 2 | throw new Exception\LocatorAlreadyBuiltException; |
|
| 33 | } |
||
| 34 | |||
| 35 | $reference = $this |
||
| 36 | 8 | ->referenceFactory |
|
| 37 | 8 | ->createReference($text); |
|
| 38 | 8 | $this->references[] = $reference; |
|
| 39 | 8 | } |
|
| 40 | |||
| 41 | 12 | public function getLocator(): LocatorInterface |
|
| 42 | { |
||
| 43 | 12 | if (!isset($this->locator)) { |
|
| 44 | 12 | $this->locator = new Locator(...$this->references); |
|
| 45 | } |
||
| 46 | |||
| 47 | 12 | return $this->locator; |
|
| 48 | } |
||
| 49 | |||
| 50 | 8 | public function export(): string |
|
| 61 | } |
||
| 62 | |||
| 63 | 6 | private function escapeReference(ListedReferenceInterface $reference): string |
|
| 70 | } |
||
| 71 | } |
||
| 72 |