Total Complexity | 5 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
13 | abstract class AbstractDocument extends AbstractModel |
||
14 | { |
||
15 | protected AbstractDocumentHandler $content; |
||
16 | |||
17 | 354 | public function __construct(Generator $generator, string $name, string $content) |
|
18 | { |
||
19 | 354 | parent::__construct($generator, $name); |
|
20 | 354 | $this->initContentFromContentString($content); |
|
21 | 352 | } |
|
22 | |||
23 | 114 | public function getContent(): AbstractDocumentHandler |
|
24 | { |
||
25 | 114 | return $this->content; |
|
26 | } |
||
27 | |||
28 | abstract protected function contentClass(): string; |
||
29 | |||
30 | 354 | protected function initContentFromContentString(string $content): AbstractDocument |
|
31 | { |
||
32 | 354 | $contentClass = $this->contentClass(); |
|
33 | 354 | $domDocument = new DOMDocument('1.0', 'utf-8'); |
|
34 | |||
35 | try { |
||
36 | 354 | $domDocument->loadXML($content, LIBXML_NOERROR); |
|
37 | 354 | $this->content = new $contentClass($domDocument, $this->generator); |
|
38 | 2 | } catch (Exception $exception) { |
|
39 | 2 | throw new InvalidArgumentException(sprintf('Unable to load document at "%s"', $this->getName()), __LINE__, $exception); |
|
40 | } |
||
41 | |||
42 | 352 | return $this; |
|
43 | } |
||
44 | |||
45 | 2 | protected function toJsonSerialize(): array |
|
48 | } |
||
49 | } |
||
50 |