Passed
Pull Request — develop (#234)
by Mikaël
49:21 queued 46:19
created

AbstractDocument   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 35
ccs 16
cts 16
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toJsonSerialize() 0 3 1
A __construct() 0 4 1
A initContentFromContentString() 0 13 2
A getContent() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\PackageGenerator\Model;
6
7
use DOMDocument;
8
use Exception;
9
use InvalidArgumentException;
10
use WsdlToPhp\PackageGenerator\Generator\Generator;
11
use WsdlToPhp\WsdlHandler\AbstractDocument as AbstractDocumentHandler;
12
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
46
    {
47 2
        return [];
48
    }
49
}
50