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