Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractDocument
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getContent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 contentClass
n/a
0 / 0
n/a
0 / 0
0
 initContentFromContentString
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 toJsonSerialize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace WsdlToPhp\PackageGenerator\Model;
6
7use WsdlToPhp\PackageGenerator\Generator\Generator;
8use WsdlToPhp\WsdlHandler\AbstractDocument as AbstractDocumentHandler;
9
10abstract class AbstractDocument extends AbstractModel
11{
12    protected AbstractDocumentHandler $content;
13
14    public function __construct(Generator $generator, string $name, string $content)
15    {
16        parent::__construct($generator, $name);
17        $this->initContentFromContentString($content);
18    }
19
20    public function getContent(): AbstractDocumentHandler
21    {
22        return $this->content;
23    }
24
25    abstract protected function contentClass(): string;
26
27    protected function initContentFromContentString(string $content): AbstractDocument
28    {
29        $contentClass = $this->contentClass();
30        $domDocument = new \DOMDocument('1.0', 'utf-8');
31
32        try {
33            $domDocument->loadXML($content, LIBXML_NOERROR);
34            $this->content = new $contentClass($domDocument, $this->generator);
35        } catch (\Exception $exception) {
36            throw new \InvalidArgumentException(sprintf('Unable to load document at "%s"', $this->getName()), __LINE__, $exception);
37        }
38
39        return $this;
40    }
41
42    protected function toJsonSerialize(): array
43    {
44        return [];
45    }
46}