XmlFileFromDomElement::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 10
c 3
b 1
f 0
dl 0
loc 17
rs 9.9332
cc 2
nc 2
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WebServCo\Framework\Files;
6
7
final class XmlFileFromDomElement extends AbstractFile implements \WebServCo\Framework\Interfaces\FileInterface
8
{
9
    public function __construct(string $fileName, \DOMElement $domElement, bool $formatOutput = false)
10
    {
11
        $domDocument = new \DOMDocument();
12
        $domDocument->preserveWhiteSpace = false;
13
        if ($formatOutput) {
14
            $domDocument->formatOutput = true;
15
        }
16
        $element = $domDocument->importNode($domElement, true);
17
        $domDocument->appendChild($element);
18
        $fileData = (string) $domDocument->saveXML();
19
20
        // phpcs:ignore SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable
21
        $domDocument = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $domDocument is dead and can be removed.
Loading history...
22
        // phpcs:ignore SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable
23
        $element = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $element is dead and can be removed.
Loading history...
24
25
        parent::__construct($fileName, $fileData, XmlFile::CONTENT_TYPE);
26
    }
27
}
28